APIs & Integrations

aaron_payne
Member

HubSpot Calls API - How to Results to Yesterday Activity Date?

Hi there,

 

I am trying to pull all call records from HubSpot from the previous day. I am trying two different end points but am unsure of what the best method is to pull these call records.

 

Endpoints

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

https://api.hubapi.com/crm/v3/objects/calls/search

 

Examples

1. I am using this enpoint that does return results but I am not sure how to filter the data to yesterday. The results seem to be from years ago and not showing the activity date of yesterday. Code below.

headers = {
'Authorization': 'Bearer xxxxxx',
'Content-Type': 'application/json'
}

properties = ["hs_call_title","activity_date"]

# Calculate the start and end timestamps for yesterday
yesterday = datetime.now() - timedelta(days=1)
start_timestamp = yesterday.strftime('%Y-%m-%d')
end_timestamp = yesterday.strftime('%Y-%m-%d')

# Specify parameters for the request
params = {
'limit': 100, # Adjust the limit as needed
'archived': False, # Exclude archived calls
'sort': 'createdAt ASC', # Sort by creation date in ascending order
'createdAt.gte': start_timestamp, # Filter calls created after the start of yesterday
'createdAt.lte': end_timestamp, # Filter calls created before the end of yesterday
'properties': properties # Include specified properties
}

# Make the API request
#response = requests.get('https://api.hubapi.com/engagements/v1/engagements/paged', headers=headers, params=params)
response = requests.get('https://api.hubapi.com/crm/v3/objects/calls', headers=headers, params=params)

 

 

Example 2

I am using the Search endpoint and getting an error with the filter groups JSON. Code below

headers = {
'Authorization': 'Bearer xxxxxxx',
'Content-Type': 'application/json'
}

# Calculate the start and end timestamps for yesterday
yesterday = datetime.now() - timedelta(days=1)
start_timestamp = yesterday.strftime('%Y-%m-%d') + "T00:00:00Z" # Start of yesterday
end_timestamp = yesterday.strftime('%Y-%m-%d') + "T23:59:59Z" # End of yesterday

# Specify parameters for the request
# Construct the search query
query = {
"filterGroups": [
{
"filters": [
{
"propertyName": "createdate",
"operator": "BETWEEN",
"value": [start_timestamp, end_timestamp]
}
]
}
],
"properties": ["hs_call_title"] # Include specified properties
}
# Make the API request
#response = requests.get('https://api.hubapi.com/engagements/v1/engagements/paged', headers=headers, params=params)
response = requests.post('https://api.hubapi.com/crm/v3/objects/calls/search', headers=headers, json=query)

 

 

What is the best way to simply pull all calls from the previous day?

0 Upvotes
2 Replies 2
Jaycee_Lewis
Community Manager
Community Manager

HubSpot Calls API - How to Results to Yesterday Activity Date?

Hey, @aaron_payne 👋 The search API is likely your best bet as it allows for filters, search operators, and sorting. The endpoint https://api.hubapi.com/crm/v3/objects/calls doesn't offer those options. 

 

Have fun building! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
aaron_payne
Member

HubSpot Calls API - How to Results to Yesterday Activity Date?

Hi Jaycee, thank  you for that information! Would it be possible to show an example code Python code block with the filters included the json query?

0 Upvotes