Error 501 (resource not available) when trying to push a notification in Angular.js

Hi, I'm trying to send a notification using Angular.js 1.3

 

My code: 

dataFactory.sendNotification = function()
{
var req = {
method: 'POST',
url: 'https://go.urbanairship.com/api/push',
headers: {
'Authorization': 'Basic <my_master_key>',
'Content-Type' : 'application/json',
'Accept' : 'application/vnd.urbanairship+json; version=3;'
},
data: {
"audience": "all",
"notification": {
"alert": "Test"
},
"device_types": "all"
}
}

$http(req).then(function (response){
// some stuff ....
});


It gives me:

XMLHttpRequest cannot load https://go.urbanairship.com/api/push. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 501.

 

Seems there's no clue to make a push (POST) by a Client (website) via API ? 

 

Didn't find what you were looking for?

New post

Comments

1 comment

  • Hi Mike,

    This is Sean with Urban Airship Technical Support.

    We don't have a Access-Control-Allow-Origin header by design. If a request is made from the client-side of a webpage it is easy for anyone with access to that webpage to pull your Master Secret or Basic Auth string.

    Other customers who have built a web based interface to send push via our API have used server-side code.

    Please let me know if you have any other questions or concerns.

    Thank you,
    Sean Conlin
    Urban Airship Technical Support
    Portland, Oregon

    Comment actions Permalink
    0

Please sign in to leave a comment.