Sunday, March 7, 2021

#835 OIC --> Connecting HubSpot with Netsuite Part 2

 Leading on from the previous post - let's go a bit more in depth into the use case.

This time I look at syncing Companies and Contacts between HubSpot and Netsuite. such integrations would be bi-directional, however, I will just cover HubSpot to Netsuite, in this simple example. One may have the requirement to surface a subset of information from one app in the other. For example, I have an Opportunity/Deal in my CRM and this is linked to a Sales Order in Netsuite. A sales person may appreciate seeing Netsuite payment details in their CRM deal page. I've closed that deal last month and the €s are coming!

In this simple scenario, I will just add a new custom field/property to the HubSpot Company object and surface this field in the UI.      

I begin by creating a Company in HubSpot - 

























I add a Contact















I check out the url - 









251 is the HubSpot id for this contact.

I check out the url when viewing the Company - 










Company id is 5566331188 

I would probably create custom fields in my Netsuite Customer and Contact objects for HubSpot customerId and contactId.

I can also do the same in HubSpot for the Netsuite Customer and Contact InternalIds.

Click on Settings -


 





Then navigate to Properties














Filter on Object







































I surface this custom field in the HubSpot UI -
































I check out the HubSpot API for updating a Company - 













I try this out in Postman - 














I check in the HubSpot UI -














Now I could also create a HubSpot Property Group, to hold those values from Netsuite I want to surface in HubSpot. This is, naturally, a more elegant solution.

Retrieving Companies from HubSpot is easy -












I try this out in Postman -



 



It returns the companyId for each Company - as the HubSpot api docs state -

This endpoint is useful when you're installing a new application and need to sync company data from HubSpot. For example, if you install an app that integrates HubSpot with an Enterprise Resource Planning app (ERP), that app may want to get all the company records stored in the CRM.

Can't get clearer than that.

Next step is to use that key to retrieve the individual companies - 



 




I try this out in Postman - 














Another option is to augment the GET All Companies request with the names of the fields needed for the Netsuite update. For example, I just need Company Name and Annual Revenue.


 






So let's try this out in OIC...

Here I use the Scheduled Pattern - 

Connection definition is as follows - 












Now to the integration itself - 














GetCompanies configuration - 
















I use the response from my Postman test for the above sample JSON.

Map to GetCompanies is as follows -

Here I click on Repeat Node to create the second Properties element -









I set the value of the first to "name" and the second to "annualrevenue" -





I then Loop over each company record returned - 








I then Log the data - this is just for the first "sanity" test - 





I activate and test - 

Firstly, here is my company list in HubSpot - 



















Now to the Activity Stream from the test run - 









































Looks good, now to the Netsuite invoke to create the companies -



 







Now to the mapping - 














The only mandatory fields are Company Name and Subsidiary.






I hard-code the Netsuite Subsidiary internalId value.







Netsuite will return the internalId of the customer created. I will use this to update the relevant HubSpot company record.






















































Map configuration -










Name is hardcoded to "c_netsuiteInternalId".

Activate and test the integration - 














Check out the new Customers in Netsuite - 










InternalId is in the url - 23919.

Check out this customer in HubSpot - 














Caveat: this simple demo does not include error handling, or initial checks to see whether the customer already exists in Netsuite. The purpose is to show how easy it is to integrate HubSpot and Netsuite using OIC. I hope I have succeeded in demonstrating this.


Improving the Integration

I then delved a bit deeper into the HubSpot apis and found the following- 











It also includes the following parameter -





So the Integration can be amended as follows - 
Add a Scheduled parameter - dateLastRun
This parameter can be set, when the customers have been successfully created in Netsuite.

It will be set to current time ala Unix timestamp - for this I use the following Javascript function - 








This returns a value such as - 


 






I create a new company in HubSpot and then try the HubSpot REST api call in Postman -





















Here is the Postman result - 










all I need to do now is update the GetCompanies invoke of HubSpot to use this api.  Please note: this api call returns a richer set of customer fields/properties.

So here it is - 





























GetCompanies new configuration - 



























The logic in the loop remains essentially the same, except for the mapping.

























The final step is to invoke the JavaScript Function.
The function (i.e. the .js file) has been uploaded to OIC -






The function can be invoked via the Javascript action - 




GetTimestamp invokes the Javascript function and then the AssignDLR action updates the scheduled parameter accordingly.

So let's test this again - 

I add 2 new companies in HubSpot -


I run the integration - 


As you can see, I set the dateLastRun parameter to 1615197058372.


dateLastRun has been updated to 1615217243645.

I submit the integration again - 


dateLastRun has been updated accordingly.






























 






No comments:

Post a Comment