I have a google chrome extension that logs in from SUGAR-CRM using XMLHttpRequest and after that, I send another GET request for fetching users data with the OAuth-Token token in the header but I am getting the Cross-Origin Resource Sharing (CORS) error:
Access to XMLHttpRequest at 'https://web-site/rest/v10/Users?order_by=first_name%3Aasc&max_num=1000&deleted=0&method=&input_type=JSON&response_type=JSON' from origin 'https://mail.google.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
My rest call function is:
function dorestCall(url, type, method, data, success_callback, error_callback, complete_callback) {
$.ajax({
url: url,
data: {
method: method,
input_type: "JSON",
response_type: "JSON",
// rest_data: data //rest data
},
type: type, //GET Request
beforeSend: function (xhr) {
if (SUGAR.OAuthToken) {
xhr.setRequestHeader("OAuth-Token", SUGAR.OAuthToken);
}
},
success: function (data, textStatus, jqXHR) {
if (success_callback) {
success_callback(data, textStatus, jqXHR);
}
},
error: function (xhr, error, errorThrown) {
console.log("in error");
if (error_callback) {
error_callback(xhr, error, errorThrown);
}
},
complete: function () {
if (complete_callback) {
complete_callback();
}
}
});
}
My Request Headers are:
Request URL: https://site-url/rest/v10/Users?order_by=first_name%3Aasc&max_num=1000&deleted=0&method=&input_type=JSON&response_type=JSON
Referrer Policy: strict-origin-when-cross-origin
Accept: application/json, text/javascript, /; q=0.01
OAuth-Token: ///token///
Referer: https://mail.google.com/
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
X-Requested-With: XMLHttpRequest
order_by: first_name:asc
max_num: 1000
deleted: 0
method:
input_type: JSON
response_type: JSON
I have tried to set dataType: "jsonp", cors: true and headers: {'Access-Control-Allow-Origin': '*',} but nothing works for me.