I want to do a post request on Google Contacts API with AngularJS $http.
I tried to do this :
var config = {
headers: {
// "Content-Type": "application/json",
"Authorization": "Bearer " + gapi.auth.getToken().access_token,
"GData-Version": "3.0"
}
}
var data = {
"test": "test"
}
$http.post('https://www.google.com/m8/feeds/contacts/default/full/', data, config);
But it returns "XMLHttpRequest cannot load https://www.google.com/m8/feeds/contacts/default/full/. Response for preflight has invalid HTTP status code 405"
This request is working (returns 201 created) on a RestClient like Postman.
If someone could explain to me why this method is not allowed from a browser.
I believe the issue is that the
https://www.google.com/m8/feeds/contacts
API simply doesn't supportOPTIONS
requests. The405
response is essentially saying the endpoint doesn't support theOPTIONS
request, not necessarily that it doesn't supportPOST
.The solution is to use Google's own JavaScript API library rather than Angular's
$http
service.There's also some documentation on how Google's API library supports CORS requests.
There may be some Angular wrapped versions of this library to make your life a little easier however I haven't dug around.