Esteban Bocic
Esteban Bocic

Reputation: 23

JSON error when sending CURL to Ionic Push notification server, error status: 422 UnprocessableEntity

This is my first approach asking for help. Let me explain the issue.

I am developing an app based on ionic. I am having trouble with the notifications.

i am trying to send this CURL test notification in debug mode but i am getting a weird error saying that the JSON is not in the correct format.

Here is the CURL:

curl -X POST -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJmYzkwOTQ2MC03MTFjLTRiZGItYjJjMC0yNWE2ZTNmNmE0YzcifQ.64U46Sfw4S9bmqz0GLpqaV-DUHJcGwoOD7oZiAgSfYI" -H "Content-Type: application/json" -d '{ "tokens": ["DEV-b673bc08-c007-422e-822f-80ed03c9b078"], "profile": “test”, "notification": { "message": ‘HELLO WORLD!’ } }' "https://api.ionic.io/push/notifications"

And this is the error the server sends back to me:

{"error": {"link": null, "type": "UnprocessableEntity", "message": "Invalid JSON in request body. For empty JSON, pass '{}'."}, "meta": {"status": 422, "request_id": "86405551-a577-4a4c-8a6b-eae65d4e4073", "version": "2.0.0-beta.0"}

My ionic info is this:

Cordova CLI: 6.1.1 Ionic Version: 1.2.4-nightly-1917 Ionic CLI Version: 1.7.14 Ionic App Lib Version: 0.7.0

Please guys if someone can help me with this it weill be much appreciated.

TY!

Upvotes: 2

Views: 1123

Answers (1)

Ariel Weinberger
Ariel Weinberger

Reputation: 2291

You were using some abnormal characters in your JSON, like and . I am not sure if it works in the code editor and in JavaScript in general, but it would be bad practice to use it.

I would recommend you use these two: ' and ".

Your original JSON:

{
    "tokens": ["DEV-b673bc08-c007-422e-822f-80ed03c9b078"],
    "profile": “test”, // <-- See the ”?
    "notification": {
        "message": ‘HELLO WORLD!’ // <-- See the `?
    }
}

Fixed JSON:

{
    "tokens": ["DEV-b673bc08-c007-422e-822f-80ed03c9b078"],
    "profile": "test",
    "notification": {
        "message": "HELLO WORLD!"
    }
}

You can paste your JSON here and make sure it's valid: http://jsonlint.com/.

It's a very common problem to confuse between the JavaScript code which is flexible in this aspect, but JSON is stricter.

Upvotes: 0

Related Questions