APIs & Integrations

sshahdev
Member

Deal search with specific property update datetime.

SOLVE

Can we have any end point available to search deals records by specific property update datetime?

Ex. I have one property 'end date' in the deal. Now I want deal records that have 'end date' property updated after specific datetime. 

0 Upvotes
1 Accepted solution
sam_baybrad
Solution
Participant

Deal search with specific property update datetime.

SOLVE

Another option - 

To search for deal records that have a specific property (like 'end date') updated after a certain datetime, you can use the HubSpot API. While there isn't a direct endpoint to search deals based on property update datetime, you can achieve this by combining the Deal API and the engagement timestamps.

Steps to Achieve This:

  1. Retrieve All Deals:

    • First, you need to retrieve all deals using the HubSpot Deals API. You can use the GET /crm/v3/objects/deals endpoint to fetch deals.
  2. Filter Deals by Property Update:

    • After retrieving the deals, you will need to filter them based on the end date property update timestamp. Unfortunately, HubSpot does not provide a direct filter in the API for this, so you will have to handle this logic in your code.

Example Implementation in Python:

Here’s an example of how you might implement this in Python:

 

import requests
from datetime import datetime

# HubSpot API key
api_key = 'YOUR_HUBSPOT_API_KEY'

# Endpoint to get all deals
url = 'https://api.hubapi.com/crm/v3/objects/deals'

# Parameters for the request
params = {
'hapikey': api_key,
'properties': 'end_date,lastmodifieddate',
'limit': 100
}

# Function to get deals from HubSpot
def get_deals(url, params):
deals = []
while url:
response = requests.get(url, params=params)
response_data = response.json()
deals.extend(response_data.get('results', []))
url = response_data.get('paging', {}).get('next', {}).get('link')
return deals

# Get all deals
all_deals = get_deals(url, params)

# Specific datetime to filter
specific_datetime = datetime.strptime('2023-01-01T00:00:00Z', '%Y-%m-%dT%H:%M:%SZ')

# Filter deals based on end_date property update
filtered_deals = []
for deal in all_deals:
end_date = deal['properties'].get('end_date')
last_modified = deal['properties'].get('lastmodifieddate')
if end_date and last_modified:
last_modified_datetime = datetime.strptime(last_modified, '%Y-%m-%dT%H:%M:%SZ')
if last_modified_datetime > specific_datetime:
filtered_deals.append(deal)

# Print filtered deals
for deal in filtered_deals:
print(deal)

 

View solution in original post

0 Upvotes
2 Replies 2
sam_baybrad
Solution
Participant

Deal search with specific property update datetime.

SOLVE

Another option - 

To search for deal records that have a specific property (like 'end date') updated after a certain datetime, you can use the HubSpot API. While there isn't a direct endpoint to search deals based on property update datetime, you can achieve this by combining the Deal API and the engagement timestamps.

Steps to Achieve This:

  1. Retrieve All Deals:

    • First, you need to retrieve all deals using the HubSpot Deals API. You can use the GET /crm/v3/objects/deals endpoint to fetch deals.
  2. Filter Deals by Property Update:

    • After retrieving the deals, you will need to filter them based on the end date property update timestamp. Unfortunately, HubSpot does not provide a direct filter in the API for this, so you will have to handle this logic in your code.

Example Implementation in Python:

Here’s an example of how you might implement this in Python:

 

import requests
from datetime import datetime

# HubSpot API key
api_key = 'YOUR_HUBSPOT_API_KEY'

# Endpoint to get all deals
url = 'https://api.hubapi.com/crm/v3/objects/deals'

# Parameters for the request
params = {
'hapikey': api_key,
'properties': 'end_date,lastmodifieddate',
'limit': 100
}

# Function to get deals from HubSpot
def get_deals(url, params):
deals = []
while url:
response = requests.get(url, params=params)
response_data = response.json()
deals.extend(response_data.get('results', []))
url = response_data.get('paging', {}).get('next', {}).get('link')
return deals

# Get all deals
all_deals = get_deals(url, params)

# Specific datetime to filter
specific_datetime = datetime.strptime('2023-01-01T00:00:00Z', '%Y-%m-%dT%H:%M:%SZ')

# Filter deals based on end_date property update
filtered_deals = []
for deal in all_deals:
end_date = deal['properties'].get('end_date')
last_modified = deal['properties'].get('lastmodifieddate')
if end_date and last_modified:
last_modified_datetime = datetime.strptime(last_modified, '%Y-%m-%dT%H:%M:%SZ')
if last_modified_datetime > specific_datetime:
filtered_deals.append(deal)

# Print filtered deals
for deal in filtered_deals:
print(deal)

 

0 Upvotes
sam_baybrad
Participant

Deal search with specific property update datetime.

SOLVE

Hi!! @sshahdev 

 

You can have this information changed via workflows for an after specific datetime

 

sam_baybrad_0-1720460583586.png

0 Upvotes