APIs & Integrations

anders_thillman
Member

POST from HubSpot to external software - where do I write my request body?

Hi

I am writing code to exchange data two-ways between HubSpot and an external softare.
I have received the answer to use WebHooks to make a HTTPRequest (eg. REST API).

Using webhooks I am now able to create (an empty) record in my external software incl basic authorization.
I want to add some data too

When using a REST call I am adding a request body like this … and here you can see how I would solve this issue in some other environment outside HubSpot


var requestBody = “{‘email’:‘anders.thillman@imydomain.com’,‘first_name’:‘Anders’,‘last_name’:‘Thillman’,‘lifecycle_stage’:‘Subscriber’}”;

var client=new XMLHttpRequest();
client.open(“post”,“https://mysoftware/api/now/table/hubspot_integration_contact_import_set”);

client.setRequestHeader(‘Accept’,‘application/json’);
client.setRequestHeader(‘Content-Type’,‘application/json’);

client.setRequestHeader(‘Authorization’, ‘Basic ‘+btoa(‘admin’+’:’+‘admin’));

client.onreadystatechange = function() {
if(this.readyState = this.DONE) {
document.getElementById(“response”).innerHTML=this.status + this.response;
}
};
client.send(requestBody);


The coding is for information only. Not part of my question.

I will use this in two different ways
1, Send data about all users to my external software (probably as a loop with multiple records - not one huge ). Thinking about a scheduled job.
2, When the single contact will update for ex lifecycle_stage - a web hook or similar will be triggered. Thinking about the single record being updated.

(FYI: Purpose is data synchronization between the two environments. The same operations will occur in my external software sending data to HubSpot)

Question:
Where in HubSpot do I add my request body-string eg. JSON field according to 1 and 2 ?

*** OR ****
Can I write my own code somewhere in HubSpot? Is the script language javascript ?
It would be nice if you want to provide an example where to write, how to call it and execute it from form submit vs. Webhook or similar.

Best Regards
Anders

0 Upvotes
1 Reply 1
markmetcoff
HubSpot Employee
HubSpot Employee

POST from HubSpot to external software - where do I write my request body?

Hey Anders,

When you’re using a Webhook (specifically, a POST-based Webhook) the information about the contact that triggered the Webhook is automatically included in the request body. You can see an example request body here:

You’ll need to parse through the request body on your end to find specific data you’re looking for.

If you absolutely MUST have a customizable request body, the only way I’m aware to do that is with Zapier - which is a third party integration with HubSpot. Zapier let’s you integrate different “apps” of which HubSpot is one. Another “app” is a Zapier Webhook. If you hook the two together, you can use HubSpot data in a more customizable webhook.

I’d recommend the first option, just to keep the overall complexity low, but the second option is there for you.

0 Upvotes