> ## Documentation Index
> Fetch the complete documentation index at: https://help.nextmatter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate with HubSpot

> Send data to and get them from HubSpot straight into your workflow.

## Before you begin

* Get a HubSport API key. To do that, you need to create a private app and set permissions for this app based on the data you want to get from HubSpot. For details, see [HubSpot documentation](https://developers.hubspot.com/docs/api/private-apps). Make sure your app has the following CRM scope: `crm.objects.deals.read`

## Get deal and contract details from HubSpot

1. In Next Matter select the workflow that should integrate with HubSpot, and add a new integration step to get deal details.

2. Click **Settings** and enter the following details:**Tip**: Get a HubSpot Deal ID. You can find the ID of a deal on the deal record itself under the property **Deal ID**.

   * **Headers**: Content-Type: application/json

   * **Headers**: Authorization: `Bearer HUBSPOT_API_KEY`

   - **Method**: POST

   - **URL**: [`https://api.hubapi.com/crm/v3/objects/deals/DEAL_ID?associations=contacts`](https://api.hubapi.com/crm/v3/objects/deals/DEAL_ID?associations=contacts)

3. Create a variable for the deal name with the value of: `$.properties.dealname` and for the contact association ID with the value of `$.associations.contacts.results[0].id`

4. Save your changes.

5. Create a new integration step to get contact details.

6. Click **Settings** and enter the following details:

   * **Method**: POST

   * **URL**: `https://api.hubapi.com/crm/v3/objects/contacts/{2. Get Deal - Integration step - contact_association_id (plain)}` The \{VALUE} is a data reference to the Next Matter variable.

   * **Headers**: Content-Type: application/json

   * **Headers**: Authorization: `Bearer HUBSPOT_API_KEY`

   * Create a variable for the contact ID with the value of: `$.id` and for the contact email with the value of `$.properties.email`, and for the contact's first name with the value of `$.properties.firstname`.

7. Save your changes.

## Search for a contact/deal in HubSpot

In Next Matter select the workflow that should integrate with HubSpot, and add a new integration step.

1. Click **Settings** and enter the following details:

   <Info>
     You can also have a step that searches HubSport for a deal by property. In this case, make a call to [https://api.hubapi.com/crm/v3/objects/deals/search](https://api.hubapi.com/crm/v3/objects/deals/search)
   </Info>

   * **Headers**: Content-Type: application/json

   * **Headers**: Authorization: `Bearer HUBSPOT_API_KEY`

   * Body:

     <CodeGroup>
       ```json theme={null}
       {
         "filterGroups": [
           {
             "filters": [
               {
                 "value": "PROPERTY_VALUE",
                 "propertyName": "PROPERTY_NAME",
                 "operator": "EQ"
               }
             ]
           }
         ]
       }
       ```
     </CodeGroup>

   - **Method**: POST

   - **URL**: [`https://api.hubapi.com/crm/v3/objects/contacts/search`](https://api.hubapi.com/crm/v3/objects/contacts/search)

2. Create a variable for the contact ID with the value of `$.results[0].id`.

   <Info>
     If you search for a deal, create a variable for deal ID with the value of `$.results[0].id`.
   </Info>

3. Save your changes.

## Create and update a HubSpot ticket

1. In Next Matter, select the process that should integrate with HubSpot, and add a new integration step to get deal details.

2. Click **Settings** and enter the following details:

   * **Method**: POST

   * **URL**: [`https://api.hubapi.com/crm/v3/objects/tickets`](https://api.hubapi.com/crm/v3/objects/tickets)

   * **Headers**: Content-Type: application/json

   * **Headers**: Authorization: `Bearer HUBSPOT_API_KEY`

   * **Body**:

     <CodeGroup>
       ```json theme={null}
       {
         "properties": {
           "hs_pipeline": "PIPELINE_ID",
           "hs_pipeline_stage": "PIPELINE_STAGE_ID",
           "hs_ticket_priority": "TICKET_PRIORITY",
           "subject": "TICKET_SUBJECT"
         }
       }
       ```
     </CodeGroup>

3. Create a variable for the `ticketID` with the value of: `$.id`.

4. Save your changes.

5. To push the ticket to the next stage, create a new integration step.

6. Click **Settings** and enter the following details:

   <Accordion title="Find HubSpot owner ID">
     1. Click the Settings cog in the main menu in HubSpot.

     2. In the left-hand menu, click **Properties**.

     3. Under **Contact properties**, type Owner in the search bar.

     4. Hover over **Contact owner** and click **View**.

     5. At the bottom of the next page, your HubSpot Owner IDs are listed in the **Dropdown options** table in the **Internal Value** column.
   </Accordion>

   * **Method**: PATCH

   * **URL**: `https://api.hubapi.com/crm/v3/objects/tickets/{2.Create Ticket - Integration Step - TicketID(plain)}?hapikey=KEY` The \{VALUE} is a data reference to the Next Matter variable. Make sure to replace the KEY variable with your HubSpot API key.

   * **Headers**: Content-Type: application/json

   * **Headers**: Authorization: `Bearer HUBSPOT_API_KEY`

   * **Body**:

     <CodeGroup>
       ```json theme={null}
       {
         "properties": {
           "hs_pipeline": "PIPELINE_ID",
           "hs_pipeline_stage": "PIPELINE_STAGE_ID",
           "hs_ticket_priority": "TICKET_PRIORITY",
           "hubspot_owner_id": "OWNER_ID",
           "subject": "{Instance name}"
         }
       }
       ```
     </CodeGroup>

7. Save your changes.
