# Examples

## List contacts & Get Contact by ID

Below is an example of a way in which you could potentially use the HubSpot connector to list all the available contacts within the database and then add each contact by their ID to a Google spreadsheet.

#### Workflow

![hb-complete-wf](https://tray.ai/documentation/images/connectors/service/hubspot/4jeLhg2fqNEfvVQQGMWUbX_hb-complete-wf.png)

#### End result

![hb-wf-end](https://tray.ai/documentation/images/connectors/service/hubspot/2mfegKKjgFhKrCJgPvJdAL_hb-wf-end.png)

### 1 - Add trigger & List contacts

Add a manual trigger and set up your HubSpot connector so that the operation is **List contacts**.
Feel free to use the fields to be more specific, for now we will be listing all available contacts to a limit of `10`.
![hb-wf-1](https://tray.ai/documentation/images/connectors/service/hubspot/6M9e0kjXqxbWbF82cQ47cC_hb-wf-1.png)

### 2 - Iterate through your list & get each contacts' ID&#x20;

A loop connector set to Loop list will go through each individual contact found.
The Next HubSpot step will identify the associated HubSpot ID for each contact found.
![hb-wf-2](https://tray.ai/documentation/images/connectors/service/hubspot/1U6a75Je5pmvnWeSUUDogi_hb-wf-2.png)
![hb-wf-3](https://tray.ai/documentation/images/connectors/service/hubspot/4HgQtC457acSvmPZD6krEi_hb-wf-3.png)

### 3 - Add to Google spreadsheet

Finally add your Google sheet step.
Make sure you already have the Google spreadsheet ID available (this is found in its URL). You will also need to specify the sheet you want your workflow to populate. You will also need to make sure your sheet has column headings already set up.
You end result should be a spreadsheet that is now populated with HubSpot contact data.
![hb-wf-4](https://tray.ai/documentation/images/connectors/service/hubspot/zJTbymRp058t7r1DoNOxZ_hb-wf-4.png)
![hb-wf-end](https://tray.ai/documentation/images/connectors/service/hubspot/2mfegKKjgFhKrCJgPvJdAL_hb-wf-end.png)

## Create / Update: Singular vs Batch

There are essentially two variations of the 'create / update' (i.e. upsert) operations. One is **singular** and the other processes data in **batches**. Both will either add information to the HubSpot database or update the fields if they already already exist.
We have briefly outlined both options in the steps below. Both examples assume that a Google sheets form has been submitted via a Tray.io form trigger, and the Google sheet information is either updated or added to the HubSpot database accordingly using one of these operations.
I would recommend using the following [Template](https://tray.io/documentation/templates/revops/export-leads-from-google-sheet-to-hubspot/) if you are looking for inspiration regarding  the beginning steps outlined above. Bear in mind that you may need to alter some parts of it in order to work with your individual use case.

#### Workflow/s

![hb-wf-complete-upsert](https://tray.ai/documentation/images/connectors/service/hubspot/3LVHGF8HjdI3ziYbbeooTL_Group%2015%20%282%29.png)

### Singular

### 1 - Create or Update contact

This examples assumes that there is a loop beyond the boolean displayed which iterates through every Google sheets row. Or rather an individual contact's information.
The Singular Upsert operation - **Create / update contact** - needs a contact's email to use as an identifier.
Each property is then individually mapped and checked to see if the information already exists in HubSpot. It will either update or 'create' (add) the information to HubSpot accordingly.
Please make sure the data mapping is correct otherwise your step will fail.
![hb-upsert-single-true-1](https://tray.ai/documentation/images/connectors/service/hubspot/2ukw14DzMg0nGAdr0jp59X_asdlfgh.png)

### Multiple

### 1 - Create & add contact details to a list

This example assumes that there is a loop beyond the boolean displayed which iterates through every Google sheets row. Or rather an individual contact's information.
With each loop the `storage-1` step adds the relevant contact fields and their respective values to the end of a list. It will first create a list to 'append to' if there is non (as would be the case with the first loop iteration).
This method is repeated until there are no more rows left and the list is essentially 'complete'.
![hb-upsert-batch-1](https://tray.ai/documentation/images/connectors/service/hubspot/4N1kdz7G8urya3u2Stt3Vp_asdlkfjh.png)

### 2 - Get list

The previous step collected the contact data into a list format.
\*\*Get value \*\*will now gather the list from the previous step via its key name (`update_list`).
![hb-upsert-batch-3](https://tray.ai/documentation/images/connectors/service/hubspot/2GatgaSE19X5gyORxVKoD8_as;dlkfhj.png)

### 3 - Batch create / update contacts

The Multiple Upsert operation - **Batch create / update contact** - will then either update or 'create' (add) all the contact details from the list into HubSpot using a singular API call.
![hb-upsert-batch-4](https://tray.ai/documentation/images/connectors/service/hubspot/6sRJvlCNgEuIMxA47WKKIO_hb-upsert-batch-4.png)

## Using the Raw HTTP Request

As of **version 4.1** you can effectively create your own operations.
To use this you will first of all need to research the endpoint in the [HubSpot API documentation](https://developers.hubspot.com/docs/reference/api) to **find the exact format** that HubSpot will be expecting the endpoint to be passed in.
Note that you will only need to add the suffix to the endpoint, as the base URL will be automatically set (the base URL is picked up from the value you entered when you first created your authentication).
The base URL for HubSpot is: `https://api.hubspot.com`
For example, say that you are using the latest version of the HubSpot connector, and the 'List All Contacts' operation did not exist. You would need to use the HubSpot API docs in order to find the relevant endpoint - which in this case is a `GET` request called: `List contacts`.
More details about this endpoint can be found [here](https://developers.hubspot.com/docs/reference/api/crm/objects/contacts).
![hubspot-get-url](https://tray.ai/documentation/images/connectors/service/hubspot/ef54dbfa-337fe08f_hubspot-get-url.png)
So if you know what your method, endpoint (and details of your query parameters are should you have any), you can get a list of current contacts available with the following settings:
**Method**: `GET`
**Endpoint**: `/crm/v3/objects/contacts`
**Body Type**: `none`
**Final outcome**: **`https://api.hubspot.com/crm/v3/objects/contacts`**

> **Info:** The v3 CRM API supports query parameters such as `limit`, `after`, and `properties` to control pagination and select which fields are returned.

![hubspot-raw-http](https://tray.ai/documentation/images/connectors/service/hubspot/ef54dbfa-23247513_aslkdjfdsf.png)
