I keep getting a “Request failed with response code 401” when trying to push via Parse.cloudCode

I have double, triple, and quadruple checked that I have the right master key that I'm passing. My parameters are taking directly from the UA website also so it can't be that. What I'm doing wrong here???

Parse.Cloud.define("sendPush", function(request, response) {

  var Buffer = require('buffer').Buffer;

  var parameters = {
    "audience" : "all",
     "device_types" : "all",
     "notification" : {
         "alert" : "Hello from Urban Airship."
     }
  };

  var params = JSON.stringify(parameters);

  Parse.Cloud.httpRequest({
    url: "https://go.urbanairship.com/api/push/",
    method: 'POST',
    headers: {
        "Content-Type" : "application/json",
        "Authorization" : 'Basic ' + new Buffer('MASTER_KEY').toString('base64'),
        "Accept" : "application/vnd.urbanairship+json; version=3;"
    },
    body: params,
    success: function(httpResponse) {
        response.error(httpResponse);
    },
    error: function(httpResponse) {
      response.error('Request failed with response code ' + httpResponse.status);
    }
  });

});

I have also tried:

"Authorization" : 'Basic ' + new Buffer('APP_SECRET:MASTER_KEY').toString('base64'),

 

Didn't find what you were looking for?

New post

Comments

2 comments

  • Hi Jeremy-

     

    Thanks for posting your issue in our forums.  It looks like you have a trailing space in your Authorization statement.  Can you try removing the trailing space after the world Basic in: 

    "Authorization" : 'Basic ' + new Buffer('APP_SECRET:MASTER_KEY').toString('base64'),?

    Could you please try the following instead?

    "Authorization" : 'Basic' + new Buffer('APP_SECRET:MASTER_KEY').toString('base64'),

    Please let us know how it goes.
    Thanks!

    Urban Airship Technical Support

     

    0
  • Thank you for your response Peter, I've tried what you've suggested and many many other combinations but nothing seems to work. I really don't know where to go with this anymore. 

    0

Please sign in to leave a comment.