HubSpot Integration – API Documentation

Requirement:  

To Integrate HubSpot with NetSuite. When creating a new deal or updating an existing deal in HubSpot we need to check the deal stage is “closed-won”. If the deal stage is “closed won” we have to create sales orders in NetSuite with “pending fulfillment status”. We must also create customers in NetSuite. In a deal, the customer information is obtained from an associate company. When the HubSpot company (NetSuite customer) does not exist on the NetSuite. Also, consider the item integration from NetSuite to HubSpot. 

Solution

HubSpot to NetSuite Integration 

  1. Initially, need to fetch all deals in Closed Won stage from NetSuite. The API endpoint used for this is: 

 POST  :  https://api.hubapi.com/crm/v3/objects/deals/search?archived=false&hapikey={api_key

Header: {Content Type: application/JSON} 

Request body: { 

  “filterGroups”: [ 

    { 

      “filters”: [ 

        { 

          “value”: “closedwon”, 

          “propertyName”: “dealstage”, 

          “operator”: “EQ” 

        }] 

    }] 

  1. In response to this POST API call, we will receive a JSON object containing all closed won deals and for each of them, we need to find out the associated company and line items 
  1. API to list the companies associated with a deal:  

GET: https://api.hubapi.com/crm/v3/objects/deals/{deal_id}/associations/companies?archived=false&hapikey={apikey

  1. API to list the line items associated with a deal  

GET: https://api.hubapi.com/crm/v3/objects/deals/{line_items}/associations/companies?archived=false&hapikey={apikey

  1. This API will return the object id of the company and item line using which we can fetch the details of both company and item lines associated with a hubspot deal. 
  1. API to fetch the company information: 

GET: https://api.hubapi.com/crm/v3/objects/companies/{company_id}?archived=false&hapikey={apikey

  1. API to fetch line item details: 

GET: https://api.hubapi.com/crm/v3/objects/line_items/{lineitem_id}?archived=false&hapikey={apikey

  1. We will create a sales order in pending fulfillment status in the NetSuite for each closed won deal. 
  1. Before creating the sales order, we need to check if the associated company of this deal exists in NetSuite as a customer. 
  1. If it exists, we will create a sales order with this customer on NetSuite. If it does not exist, we will create a new customer in NetSuite using the company details fetched from HubSpot (API is mentioned above) 
  1. In the sales order, the item should be in the same order as in the HubSpot deal. 
  1. Before setting the item line in sales order, we will check if the item already exists or not in NetSuite. 
  1. If it exists, we will add this item to the sales order item sub list. If it does not exist, we will note create the item in netsuite, instead we will send an error mail to an employee at vertex chemicals.  

NetSuite to HubSpot Integration 

  1. When a salesorder created for a hubspot deal is changed to status ‘Pending Fulfilled’ or ‘Partially Billed/Pending Fulfillment’, then need to change the deal stage to ‘Pending Fulfillment’ in hubspot. 
  1. For this, we will deploy a user event script in the item fulfillment record, and whenever an IF is created, we will call an API to update the deal stage. 
  • For updating the deal stage, we need to identify which pipeline the deal is and identify the pipeline id and stage id as well. 
  • API to fetch all pipelines and their stages in a hubspot account:  

GET: https://api.hubapi.com/crm/v3/pipelines/deals?hapikey={apikey} 

  • Using these informations we will set up 2 custom records in netsuite for handling the pipelines and their stages. 
  1. After identifying the pipeline id and stage id of the stage ‘Pending Fulfilled’, we will update the deal stage. 
  • API for that: 

PATCH: https://api.hubapi.com/crm/v3/objects/deals/8716770395?archived=false&hapikey={apikey

  1. Similarly, when the status of the SO changes to ‘Pending billing’ or ‘Billed’, we need to update the deal stage to ‘Dispatch’ 
  1. When the SO is closed, need to update the deal stage to ‘closed lost’ 
  1. When a new item is created in netsuite, we will create this item in hubspot 
  • API to create item line in hubspot: 

POST: https://api.hubapi.com/crm/v3/objects/line_items?archived=false&hapikey={apikey

Sample request body: 

  “properties”: { 

    “name”: “1 year implementation consultation”, 

    “hs_product_id”: “151019648”, 

    “quantity”: “2”, 

    “price”: “6000.00” 

  } 

  1. Similarly, when a new customer is created in netsuite, we will create a corresponding company in HubSpot 
  • API to create company: 

POST: https://api.hubapi.com/crm/v3/objects/companies?archived=false&hapikey={apikey

Sample request body: 

  “properties”: { 

    “city”: “Cambridge”, 

    “domain”: “biglytics.net”, 

    “industry”: “Technology”, 

    “name”: “Biglytics”, 

    “phone”: “(877) 929-0687”, 

    “state”: “Massachusetts” 

  } 

  1. API to test the API usage:  

GET: https://api.hubapi.com/integrations/v1/limit/daily?hapikey={apikey

Leave a comment

Your email address will not be published. Required fields are marked *