Create companies using XMLHttpRequest returning 400 Error
SOLVE
I am attempting to create a company using the api, but I am getting a 400 error. Followed the api docs for expected params, so not sure why it is deemed a bad request.
var url='https://api.hubapi.com/companies/v2/companies?hapikey=';
var params = '{"properties": [{"name": "name","value": "OK Company"}, {"name": "description","value": "Ok company" }]}';
var xhr = new XMLHttpRequest();
var json = JSON.stringify(params);
alert(json);
Create companies using XMLHttpRequest returning 400 Error
SOLVE
Thanks for responding @Derek_Gervais. I am aware of the CORS limitation, and I am working around it for testing, also using the test portal, when the application is live, I will make the request on an external server.
I solved my issue in case anyone else runs into it. The script was escaping my param arguments and which was causing a malformed json.
Create companies using XMLHttpRequest returning 400 Error
SOLVE
Thanks for responding @Derek_Gervais. I am aware of the CORS limitation, and I am working around it for testing, also using the test portal, when the application is live, I will make the request on an external server.
I solved my issue in case anyone else runs into it. The script was escaping my param arguments and which was causing a malformed json.
Are you trying to make this request client-side? The HubSpot APIs don't support support cross-origin (CORS) AJAX requests. Making the request client-side using JavaScript would expose any authentication you're using for the request. In order to use JavaScript/AJAX, you'll need to make the request (excluding any authentication) to an external server that could then add the needed authentication and make requests to HubSpot's APIs server-side.