Hi,
I have written a Python script to extract data from HubSpot using ACCESS TOKEN.
I encountered problem on extracting data based on last modified date as shown below.
import requests
from datetime import datetime
dt_str = datetime(2022,10,1,0,0,0).strftime('%Y-%m-%d')
url = 'https://api.hubapi.com/crm/v3/objects/contacts/search'
headers = {'content-type' : 'application/json',
'authorization' : 'Bearer %s' % access_token}
data = {'filterGroups' : [{'filters' : [{'propertyName' : 'lastmodifieddate',
'operator' : 'GTE',
'value' : dt_str}]}]}
response = requests.request('POST', url, headers=headers, json=data)
print(response)
The problem is
<Response [400]>
However, I do not encounter problem of extracting data based on last name and first name as shown below.
import requests
url = 'https://api.hubapi.com/crm/v3/objects/contacts/search'
headers = {'content-type' : 'application/json',
'authorization' : 'Bearer %s' % access_token}
data = {'filterGroups' : [{'filters' : [{'propertyName' : 'lastname',
'operator' : 'EQ',
'value' : 'Wong'}]}],
'sorts' : [{'propertyName' : 'lastmodifieddate',
'direction' : 'DESCENDING'}]}
response = requests.request('POST', url, headers=headers, json=data)
for i in range(10):
print(response.json()['results'][i])
print()
import requests
url = 'https://api.hubapi.com/crm/v3/objects/contacts/search'
headers = {'content-type' : 'application/json',
'authorization' : 'Bearer %s' % access_token}
data = {'filterGroups' : [{'filters' : [{'propertyName' : 'firstname',
'operator' : 'EQ',
'value' : 'John'}]}]}
response = requests.request('POST', url, headers=headers, json=data)
for i in range(5):
print(response.json()['results'][i])
print()
Hope to get advice on how I can proceed.
Thank you very much for any help rendered.
John