Contact api call ; CORS / Ajax request / error

contacts

#1

I am stuck with similar issue, My motive is simple to get data from crm, using hubspot api,

I did try to use ajax, dataType: “json”,
$.ajax({
type:“GET”,

dataType: “json”,
jsonpCallback:‘callback’,

url:"https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=1232-sfesfe-a323432-23423423-fsf"
success: function(data) {
// console.log(data);
},
error: function() {
console.log(“fail”);
// alert();
}

});

Result I got cross origin error :slight_smile:
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

I used datatype : jsonp
$.ajax({
type: “GET”,

dataType: “jsonp”,
jsonp: “callback”,
crossOrigin: true,
jsonpCallback: “my_callback”,
url: “https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=1232-sfesfe-a323432-23423423-fsf”,
headers:{“Content-Type”:“text/html; charset=utf-8”},
cors:false,
success: function(data) {

console.log(data);

},
error: function() {
console.log(“fail”);

}
Result : I got error
“Uncaught SyntaxError: Unexpected token : ”

------------------------------------------------------ its been like 3 days to figure outo some thing

On our blog pages we need to pull data from crm, contact details, and on basis of these details we need to create blog post dynamically;

@nagavalli @pmanca , we do get data on console,

why you have https://developers.hubspot.com/docs/methods/contacts/get_contacts

if we can’t use it, I need to pull user data, by making call to crm
https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=demo

being on same domain it dosen’t help::


#2

@ume.a We only accept server-side requests and do not allow client-side or cross-origin requests.