APIs & Integrations

nishashah
Member

Problem with sending ajax request for create new contact

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?

0 Upvotes
1 Reply 1
Dadams
HubSpot Employee
HubSpot Employee

Problem with sending ajax request for create new contact

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.

0 Upvotes