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

aaron_payne
Member

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
3 Replies 3
Jaycee_Lewis
Thought Leader

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





loop


Loop Marketing is a new four-stage approach that combines AI efficiency and human authenticity to drive growth.

Learn More




0 Upvotes
aaron_payne
Member

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
halice
HubSpot Employee
HubSpot Employee

Hi-

 

I know some time has passed since your post, but in case anyone has a similar question in the future.

 

This is JSON that worked for me - I specified the date using the GTE and LT operators for the time filters:

{
  "filterGroups": [
    {
      "filters": [
        {
          "propertyName": "hs_timestamp",
          "operator": "GTE",
          "value": 1758204000000 // ms UNIX timestamp at 0:00 am
        },
        {
          "propertyName": "hs_timestamp",
          "operator": "LTE",
          "value": 1758290400000 // ms UNIX timestamp at 0:00 am of the following day
        }
      ]
    }
  ],
  "properties": ["hubspot_owner_id"],
  "limit": 100,
  "after": 0
}


Hope this helps someone!