What will you learn?

  1. Private apps
  2. Defining scopes
  3. API Integration
  4. Create new property
  5. How to get and post Email Engagement

Private apps:

Currently, no API key is used for authentication. Private apps are replacing API keys. Instead of API keys, private apps utilize secure access tokens.

  • Create a private app (Settings → Account setup → Integrations → Private App). (access token will be generated)
  • Then use `Bearer <access_token>’ as an authorization key.

Defining scopes:

  • Scopes determine what our app can access and do in HubSpot. It's strongly encouraged to require as few scopes as possible for our app's functionality.
  • Scopes can be defined while creating private apps. It set the permissions for what to do and what not to do with that generated access token as below:

API Integration:

Get an individual record: 

GET https://api.hubapi.com/crm/v3/objects/contacts/<id>
{
   "id": "1",
   "properties": {
       "createdate": "2023-01-13T06:36:56.100Z",
       "email": "emailmaria@hubspot.com",
       "firstname": "Maria",
       "hs_object_id": "1",
       "lastmodifieddate": "2023-01-13T06:37:11.880Z",
       "lastname": "Johnson (Sample Contact)"
   },
   "createdAt": "2023-01-13T06:36:56.100Z",
   "updatedAt": "2023-01-13T06:37:11.880Z",
   "archived": false
}

Get all records: 

GET https://api.hubapi.com/crm/v3/objects/contacts
{
   "results": [
       {
           "id": "1",
           "properties": {
               "createdate": "2023-01-13T06:36:56.100Z",
               "email": "emailmaria@hubspot.com",
               "firstname": "Maria",
               "hs_object_id": "1",
               "lastmodifieddate": "2023-01-13T06:37:11.880Z",
               "lastname": "Johnson (Sample Contact)"
           },
           "createdAt": "2023-01-13T06:36:56.100Z",
           "updatedAt": "2023-01-13T06:37:11.880Z",
           "archived": false
       },
       {
           "id": "51",
           "properties": {
               "createdate": "2023-01-13T06:36:56.450Z",
               "email": "bh@hubspot.com",
               "firstname": "Brian",
               "hs_object_id": "51",
               "lastmodifieddate": "2023-01-13T06:37:04.014Z",
               "lastname": "Halligan (Sample Contact)"
           },
           "createdAt": "2023-01-13T06:36:56.450Z",
           "updatedAt": "2023-01-13T06:37:04.014Z",
           "archived": false
       },
       {
           "id": "101",
           "properties": {
               "createdate": "2023-01-13T06:39:23.558Z",
               "email": "ishwar0123@gmail.com",
               "firstname": "Ishwar",
               "hs_object_id": "101",
               "lastmodifieddate": "2023-01-16T04:17:42.923Z",
               "lastname": "Gautam"
           },
           "createdAt": "2023-01-13T06:39:23.558Z",
           "updatedAt": "2023-01-16T04:17:42.923Z",
           "archived": false
       },
       {
           "id": "151",
           "properties": {
               "createdate": "2023-01-13T07:35:05.788Z",
               "email": "joeroot@gmail.com",
               "firstname": "Joe",
               "hs_object_id": "151",
               "lastmodifieddate": "2023-02-02T04:29:45.282Z",
               "lastname": "Done"
           },
           "createdAt": "2023-01-13T07:35:05.788Z",
           "updatedAt": "2023-02-02T04:29:45.282Z",
           "archived": false
       },
       {
           "id": "251",
           "properties": {
               "createdate": "2023-01-16T08:38:51.985Z",
               "email": "amit1227@gmail.com",
               "firstname": "Amit Prasad",
               "hs_object_id": "251",
               "lastmodifieddate": "2023-01-18T06:12:33.449Z",
               "lastname": "Gautam"
           },
           "createdAt": "2023-01-16T08:38:51.985Z",
           "updatedAt": "2023-01-18T06:12:33.449Z",
           "archived": false
       },
       {
           "id": "651",
           "properties": {
               "createdate": "2023-01-19T12:49:48.025Z",
               "email": "bijaygautam@gmail.com",
               "firstname": "Bijay",
               "hs_object_id": "651",
               "lastmodifieddate": "2023-01-19T12:52:11.862Z",
               "lastname": "Gautam"
           },
           "createdAt": "2023-01-19T12:49:48.025Z",
           "updatedAt": "2023-01-19T12:52:11.862Z",
           "archived": false
       },
       {
           "id": "701",
           "properties": {
               "createdate": "2023-01-24T07:09:19.384Z",
               "email": "bijaypaudel@hubspot.com",
               "firstname": "Bijay",
               "hs_object_id": "701",
               "lastmodifieddate": "2023-01-24T07:09:23.109Z",
               "lastname": "Poudel (Sample Contact)"
           },
           "createdAt": "2023-01-24T07:09:19.384Z",
           "updatedAt": "2023-01-24T07:09:23.109Z",
           "archived": false
       }
   ]
}

Some of the other requests are:

  • Add a record: POST https://api.hubapi.com/crm/v3/objects/contacts
  • Update a record: PATCH https://api.hubapi.com/crm/v3/objects/contacts/<id>
  • Delete a record: DELETE https://api.hubapi.com/crm/v3/objects/contacts/<id>

Body for POST and PATCH requests (example):

{
   "properties": {
       "email": "jonedoe@hubspot.com",
       "firstname": "Jone",
       "lastname": "Doe (Sample Contact)"
   }
}

 

Get all deals:

https://api.hubapi.com/crm/v3/objects/deal

{
   "results": [
       {
           "id": "11742595446",
           "properties": {
               "amount": "2000",
               "closedate": "2023-01-31T10:53:36.688Z",
               "createdate": "2023-01-18T10:53:55.901Z",
               "dealname": "My deal",
               "dealstage": "appointmentscheduled",
               "hs_lastmodifieddate": "2023-01-24T05:59:59.556Z",
               "hs_object_id": "11742595446",
               "pipeline": "default"
           },
           "createdAt": "2023-01-18T10:53:55.901Z",
           "updatedAt": "2023-01-24T05:59:59.556Z",
           "archived": false
       },
       {
           "id": "11863944554",
           "properties": {
               "amount": "900",
               "closedate": "2023-01-31T07:50:17.375Z",
               "createdate": "2023-01-26T07:50:34.307Z",
               "dealname": "Another deal",
               "dealstage": "appointmentscheduled",
               "hs_lastmodifieddate": "2023-01-26T07:50:36.281Z",
               "hs_object_id": "11863944554",
               "pipeline": "default"
           },
           "createdAt": "2023-01-26T07:50:34.307Z",
           "updatedAt": "2023-01-26T07:50:36.281Z",
           "archived": false
       }
   ]
}

Create new Property:

We can also create a new property through Settings → Data Management → Properties → Create property or click on a particular record → View all properties → Manage Properties → Create property.

Get skills from deals:

  • When we call API, only default properties will get fetched.
  • So, we also need to pass query parameters to get particular properties.

e.g. https://api.hubapi.com/crm/v3/objects/deal?properties=skill

{
   "results": [
       {
           "id": "11742595446",
           "properties": {
               "createdate": "2023-01-18T10:53:55.901Z",
               "hs_lastmodifieddate": "2023-01-24T05:59:59.556Z",
               "hs_object_id": "11742595446",
               "skill": "React;Python"
           },
           "createdAt": "2023-01-18T10:53:55.901Z",
           "updatedAt": "2023-01-24T05:59:59.556Z",
           "archived": false
       },
       {
           "id": "11863944554",
           "properties": {
               "createdate": "2023-01-26T07:50:34.307Z",
               "hs_lastmodifieddate": "2023-01-26T07:50:36.281Z",
               "hs_object_id": "11863944554",
               "skill": null
           },
           "createdAt": "2023-01-26T07:50:34.307Z",
           "updatedAt": "2023-01-26T07:50:36.281Z",
           "archived": false
       }
   ]
}

 

Get multiple properties with a value:

https://api.hubapi.com/crm/v3/objects/deal?properties=skill,amount

{
   "results": [
       {
           "id": "11742595446",
           "properties": {
               "amount": "2000",
               "createdate": "2023-01-18T10:53:55.901Z",
               "hs_lastmodifieddate": "2023-01-24T05:59:59.556Z",
               "hs_object_id": "11742595446",
               "skill": "React;Python"
           },
           "createdAt": "2023-01-18T10:53:55.901Z",
           "updatedAt": "2023-01-24T05:59:59.556Z",
           "archived": false
       },
       {
           "id": "11863944554",
           "properties": {
               "amount": "900",
               "createdate": "2023-01-26T07:50:34.307Z",
               "hs_lastmodifieddate": "2023-01-26T07:50:36.281Z",
               "hs_object_id": "11863944554",
               "skill": null
           },
           "createdAt": "2023-01-26T07:50:34.307Z",
           "updatedAt": "2023-01-26T07:50:36.281Z",
           "archived": false
       }
   ]
}

 

Filter the data by amount:

Post https://api.hubapi.com/crm/v3/objects/deals/search

Request Body:

{
   "filterGroups":[
     {
       "filters":[
         {
           "propertyName": "amount",
           "operator": "EQ",
           "value": "2000"
         }
       ]
     }
   ]
}

The response will be:

{
   "total": 1,
   "results": [
       {
           "id": "11742595446",
           "properties": {
               "amount": "2000",
               "closedate": "2023-01-31T10:53:36.688Z",
               "createdate": "2023-01-18T10:53:55.901Z",
               "dealname": "My deal",
               "dealstage": "appointmentscheduled",
               "hs_lastmodifieddate": "2023-01-24T05:59:59.556Z",
               "hs_object_id": "11742595446",
               "pipeline": "default"
           },
           "createdAt": "2023-01-18T10:53:55.901Z",
           "updatedAt": "2023-01-24T05:59:59.556Z",
           "archived": false
       }
   ]
}

Filter the data by created date:

Post https://api.hubapi.com/crm/v3/objects/deals/search

Request Body:

{
   "filterGroups":[
     {
       "filters":[
         {
           "propertyName": "createdate",
           "operator": "BETWEEN",
           "highValue": "1774719434000",
           "value": "1574719434000"
         }
       ]
     }
   ]
}

Note

  • highvalue and value take the date in the epoch (in milliseconds).
  • The Unix epoch counts the number of seconds elapsed since January 1, 1970, at midnight UTC, excluding leap seconds.

There are a lot of online tools available to convert human-readable date to epochs. For e.g. epochconverter.com

The response will be:

{
   "total": 2,
   "results": [
       {
           "id": "11742595446",
           "properties": {
               "amount": "2000",
               "closedate": "2023-01-31T10:53:36.688Z",
               "createdate": "2023-01-18T10:53:55.901Z",
               "dealname": "My deal",
               "dealstage": "appointmentscheduled",
               "hs_lastmodifieddate": "2023-01-24T05:59:59.556Z",
               "hs_object_id": "11742595446",
               "pipeline": "default"
           },
           "createdAt": "2023-01-18T10:53:55.901Z",
           "updatedAt": "2023-01-24T05:59:59.556Z",
           "archived": false
       },
       {
           "id": "11863944554",
           "properties": {
               "amount": "900",
               "closedate": "2023-01-31T07:50:17.375Z",
               "createdate": "2023-01-26T07:50:34.307Z",
               "dealname": "Another deal",
               "dealstage": "appointmentscheduled",
               "hs_lastmodifieddate": "2023-01-26T07:50:36.281Z",
               "hs_object_id": "11863944554",
               "pipeline": "default"
           },
           "createdAt": "2023-01-26T07:50:34.307Z",
           "updatedAt": "2023-01-26T07:50:36.281Z",
           "archived": false
       }
   ]
}

For more information, click here

How to GET and POST email engagement?