I`m using Rails and https://github.com/zaru/webpush gem and have configured things according to this guide https://rossta.net/blog/web-push-notifications-from-rails.html
I manage to register ServiceWorker and get subscription. I save it like this in controller
endpoint = params[:subscription][:endpoint]
p256dh = params[:subscription][:keys][:p256dh]
auth = params[:subscription][:keys][:auth]
current_user.gcm_endpoint = endpoint
current_user.gcm_p256dh = p256dh
current_user.gcm_auth = auth
Later I send the message like this:
message = {
title: "Title",
body: "This is a test notification",
icon: "images/my-128.png"
}
Webpush.payload_send(
endpoint: current_user.gcm_endpoint,
message: JSON.generate(message),
p256dh: current_user.gcm_p256dh,
auth: current_user.gcm_auth,
ttl: 600,
api_key: "<MY API KEY>"
)
I have configured and activated account on Google Console. I have turned on GCM API and added a correct key. But no matter what I do, I receive this 400 error code. And I have no stats in Google console - as if no calls are made to my API call.
The problem was in the key itself. Need to generate it using a separate Firebase control panel. Here With that key my code works well.