Hi,
I am looking to import events from HubSpot into our company software via an API.
We need to know how to use the API within HubSpot to export all the contacts who has an activity within the last week and have them imported into our company software.
Thank you !
Shaunt
Hello @SHosdaghian
Create a HubSpot API key.
Create a filter to select the contacts who have an activity within the last week.
Use the HubSpot API to export the contacts who match the filter.
Import the exported contacts into your company software.
Here are the details for each step:
Step 1: Create a HubSpot API key.
To create a HubSpot API key, go to your HubSpot account and navigate to Settings > APIs & Apps > Tokens. Click Create Token and select the HubSpot OAuth 2.0 scope.
Step 2: Create a filter to select the contacts who have an activity within the last week.
To create a filter, you can use the HubSpot Search API. The following is an example of a filter that would select the contacts who have an activity within the last week:
{
"filterGroups": [
{
"filters": [
{
"value": "7",
"propertyName": "lastActivityDate",
"operator": "GTE"
}
]
}
]
}
Use the HubSpot API to export the contacts who match the filter.
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"objects": ["contacts"],
"filters": [
{
"value": "7",
"propertyName": "lastActivityDate",
"operator": "GTE"
}
],
"nextPageToken": null
}' \
https://api.hubspot.com/crm/v3/objects/contacts/exports
Once you have exported the contacts, you can import them into your company software. The specific steps for importing the contacts will vary depending on your company software.
Hi Himanshu,
Thank you for your assistance.
I tried with the tool “postman”
POST https://api.hubspot.com/crm/v3/objects/contacts/exports
HEADER
“Content-Type”: “application/json”
“Authorization” : "Bearer " + APITOKEN
BODY
{
“objects”: [“contacts”],
“filters”: [
{
“value”: “7”,
“propertyName”: “lastActivityDate”,
“operator”: “GTE”
}
],
“nextPageToken”: null
}
the result is :
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html;charset=utf-8”/>
<title>Error 405 Method Not Allowed</title>
</head>
<body><h2>HTTP ERROR 405</h2>
<p>Reason:
<pre> Method Not Allowed</pre></p>
</body>
</html>
Perhaps I am doing something wrong?
How to export data from HubSpot using a filter (via API)
Hi Himanshu,
Thank you for your assistance.
I tried with the tool “postman”
POST https://api.hubspot.com/crm/v3/objects/contacts/exports
HEADER
“Content-Type”: “application/json”
“Authorization” : "Bearer " + APITOKEN
BODY
{
“objects”: [“contacts”],
“filters”: [
{
“value”: “7”,
“propertyName”: “lastActivityDate”,
“operator”: “GTE”
}
],
“nextPageToken”: null
}
the result is :
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html;charset=utf-8”/>
<title>Error 405 Method Not Allowed</title>
</head>
<body><h2>HTTP ERROR 405</h2>
<p>Reason:
<pre> Method Not Allowed</pre></p>
</body>
</html>
Perhaps I am doing something wrong?