Hello i am using box api to for integration they have given just curl to get access token which is as follow
curl https://www.box.com/api/oauth2/token \
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \
-X POST
I want to get access token using jquery ajax request i have tired my code like this as follow :
var data2= '{"grant_type":"authorization_code", "client_id":"READACTED" ,"client_secret":"Redacted" ,"code" :"'+code+'"}';
var data1 = JSON.parse(data2);
$.ajax({
type: 'POST',
url: "https://www.box.com/api/oauth2/token",
data: data1,
success: function(json) {
console.log(e);
alert("success"+json);
},
error: function(e) {
console.log(e)
alert("Failure"+ JSON.stringify(e));
}
});
I am facing problem with this request as it gives me error in browser console :
XMLHttpRequest cannot load https://www.box.com/api/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
please tell me where i am wrong it is working fine with Postman client .
In order to get past the same-origin policy, you'll need to contact Box support team. You can either email api@box.com or follow the "Box Community" link on the Box webpage in the lower right side.
The support team will ask you for the origin URL or URLs that you want to use (Box does not allow wildcard origins) in the CORS header. They will also need to know your application name, or API Key to lookup your app and setup your CORS headers for you.