Problem with sending ajax request for create new contact


#1

Hi All,

I have just setup my developer account and trying to create new contact with ajax json request. Below is code i am using.

function createContact() {
var properties = [{ “property”: “email”, “value”: "nisha.shah@yahoo.com" }, { “property”: “firstname”, “value”: “nisha” },
{ “property”: “lastname”, “value”: “shah” }]
debugger;
$.ajax({
url: ‘https://api.hubapi.com/contacts/v1/40040/contact/?hapikey=’,
data: JSON.stringify(properties),
type: ‘Post’,
timeout: 5000,
success: function (data) {
alert(data);
return false;
},
error: function (data) {
alert(data.status);
}
})
}

I am always getting message from error. no success. Any idea what’s wrong with my code? does anyone have working example with ajax post request from html page?


#2

Hi @nishashah

Our APIs do not support cross-origin AJAX requests, as it risks exposing whatever authentication you’re using to your visitors. Any requests to our APIs need to be made server-side.