kater
kater

Reputation: 139

FCM api 'Bad request 400' error

I'm trying to implement sending notifications via new FCM api protocols. I went through authenticating requests, I enabled api in google console as well. Now when I send request I'm receiving Bad request 400 error. Response doesn't contain any other information than error code and error message. Even reason field says 'Bad Request'. I'm implementing it with FCM api docs.

def fcm_test():
    FCM_URL = "https://fcm.googleapis.com/v1/projects/MY_PROJECT_NAME/messages:send"
    my_token = "device-token"

    payload = {
        "massage": {
            "token": my_token,
            "notification": {
                "body": "body",
                "title": "title"
            }
        }
    }

    payload = json.dumps(payload)
    headers = {
        "Authorization": "Bearer {auth_token}".format(auth_token=_get_authentication_token()),
        "Content-Type": "application/json; UTF-8",
    }
    try:
        request = moves.urllib.request.Request(FCM_URL, payload.encode('utf-8'), headers)
        response = moves.urllib.request.urlopen(request, timeout=10)
    except Exception as e:
        pass
    return

Upvotes: 2

Views: 5916

Answers (1)

mshroyer
mshroyer

Reputation: 1968

There's a typo in your payload key, can you try it again with "message" instead of "massage"?

Upvotes: 6

Related Questions