I am having a hard time figuring out how to specify the headers for a push notification post request.

I am sending the following:

Authorization AppKey:<My app secret>

Content-Type  application/json

Accept application/vnd.urbanairship+json; version=3

Passing the following json payload:  

{"audience":"all", "device_types": ["ios", "android"], "notification": { "ios": { "alert": "Hi World"}}}


I keep getting a 401 error saying that it's not authorized.  I think it has something to do with the way I am specifying the app key.  Could someone please show me how it should be written?





Didn't find what you were looking for?

New post



  • Also, I am posting to: https://go.urbanairship.com/api/push/

    Comment actions Permalink
  • Hi Lewis,

    You should define your Authorization as "APP_KEY:MASTER_SECRET". You'll need your Master Secret for the API endpoint you are using. For example, if I was sending your request using cURL it would look something like:


    curl -X POST \
    -H "Content-type: application/json" \
    -H "Accept: application/vnd.urbanairship+json; version=3;" \
    --data '{"audience":"all", "device_types": ["ios", "android"],
    "notification": { "ios": { "alert": "Hi World"}}}'


    I hope that makes sense. 

    Comment actions Permalink
  • Hi Aiden,

    Thanks for the answer.  I am not using curl.  I tried APP_KEY:My master secret

    and it didn't work.  I am still getting the 401 error.

    Do you have an example of a http post request?



    Comment actions Permalink
  • Okay, so firstly, you probably want to base64 encode your authorisation string i.e. APP_KEY:MASTER_SECRET. Then, your request should look something like this:

    POST /api/push/ HTTP/1.1
    Host: go.urbanairship.com
    Content-Type: application/json
    Accept: application/vnd.urbanairship+json; version=3;
    Authorization: Basic BASE64_ENCODED_AUTH

    {"audience":"all", "device_types": ["ios", "android"], "notification": { "ios": { "alert": "Hi World"}}}

    Please let me know if this helps.

    Comment actions Permalink

Please sign in to leave a comment.