This is the request:

var header = {'Authorization': 'Basic 123456', // master api key
'content-type': 'application/json; charset=utf-8',
'Accept': 'application/vnd.urbanairship+json; version=3'
};
var data = {
"audience": {
"OR": [
{"android_channel": 'e774efea-1c2e-4a55-9abf-e1e8bbab644d'},
{"ios_channel": 'e774efea-1c2e-4a55-9abf-e1e8bbab644d'}
]
},
"notification": {
"alert": "Hello!"
},
"device_types": "all"
};
Meteor.http.post('https://go.urbanairship.com/api/push HTTP/1.1', {headers: header, data: data}, function(err, results){
if(err)console.log('err' + err);
console.log(results)
});


and this is the response I get:
errError: failed [404] Error 404
{ statusCode: 404,
 content: 'Error 404',
 headers:
{ server: 'Apache/2.2.15 (CentOS)',
 'content-length': '9',
 'content-type': 'text/html; charset=iso-8859-1',
date: 'Sun, 12 Feb 2017 19:58:50 GMT',
 connection: 'close' },
 data: null }
Can you see the problem? Also the reason I am using "or" in the audience is instead of looking up for the device type. is that a valid solution?
Thanks

Didn't find what you were looking for?

New post

Comments

7 comments

  • Hi Gil,

    I believe the URL you are targeting is not correct.

    Currently, it is "https://go.urbanairship.com/api/push HTTP/1.1"

    Go ahead and remove the HTTP bit such that the URL you have left is simply "https://go.urbanairship.com/api/push"

    Comment actions Permalink
    0
  • Thanks,

    I made the change now I am getting:

    errError: failed [401] {"ok":false,"error":"Unauthorized","error_code":40101}
    k6yd2017-02-13 19:33:43+02:00{ statusCode: 401,
    k6yd2017-02-13 19:33:43+02:00 content: '{"ok":false,"error":"Unauthorized","error_code":40101}',
    k6yd2017-02-13 19:33:43+02:00 headers:
    k6yd2017-02-13 19:33:43+02:00 { 'www-authenticate': 'Basic realm="API"',
    k6yd2017-02-13 19:33:43+02:00 'content-type': 'application/vnd.urbanairship+json;version=3',
    k6yd2017-02-13 19:33:43+02:00 'content-length': '54',
    k6yd2017-02-13 19:33:43+02:00 date: 'Mon, 13 Feb 2017 17:33:43 GMT',
    k6yd2017-02-13 19:33:43+02:00 connection: 'close' },
    k6yd2017-02-13 19:33:43+02:00 data: null }
    Comment actions Permalink
    0
  • Gil,

    Typically a 401 error occurs if your authentication is incorrect.

    Are you making sure to use the App Key and Master Secret combination when sending the request? 

    Additionally, when sending the App Key and Master Secret combination, make sure it is base64 encoded when sending it with the "Basic" authorization.

    Comment actions Permalink
    0
  • Hi,

    No, I don't do combination. How do I do the combination?

    I am only using the App Master Secret (123456):

    var header = {'Authorization': 'Basic 123456', // master api key
    'content-type': 'application/json; charset=utf-8',
    'Accept': 'application/vnd.urbanairship+json; version=3'
    };

     

    Comment actions Permalink
    0
  • Gil,

    The App Secret, Master Secret combination is pretty simple. Following the documentation suggestions, it would simply be a string that would look like "<AppKey>:<MasterSecret>". Then, pass that string as a base64 encoded string into your program.

    So, for example, you might have something that looks like: 

    //Python

    import base64
    var authString = "Insert your app key here:Insert your master secret here";

    encodedString = base64.b64encode(encodedString.encode())

    var header = {'Authorization': 'Basic <encodedString goes here>', 
    'content-type': 'application/json; charset=utf-8',
    'Accept': 'application/vnd.urbanairship+json; version=3'
    };


    Also, please be sure you're using a valid App Key and Master Secret. You can obtain these by navigating to the "APIs & Integrations" page of your Urban Airship dashboard settings. You won't be able to authenticate properly without the proper credentials for your app.

     

    Comment actions Permalink
    1
  • Thanks a lot, 

    FYI,  in the documentation link you shared i don't see any mention of 'base64' or 'combination', or any part of your explanation, unless I am totally missing it :)

    Thanks again.

     

    Comment actions Permalink
    0
  • Gil,

    The documentation states: "API requests are identified using HTTP basic authentication. The username portion is the application key. The password portion is either the application secret, or master secret."

    The Basic authentication is typically Base64 encoded, as the link suggests.

    Comment actions Permalink
    0

Please sign in to leave a comment.