I want to fetch a list in hubspot. I used below program. It is giving error. Also is there any issue with v1 api?
Error occurred during API request: 401 {"status":"error","message":"This hapikey doesn't exist.","correlationId":"2c43fca5-6bf2-4f99-89d2-833282530054"}
When i use api key to fetch contacts,deals and companies it is working but not with lists. Below i provided program for reference. Please give suggestion.
import requests
from datetime import datetime, timedelta
api_key = “”
list_id = 1234
# Calculate the date range for the previous day
specific_date = datetime.now() - timedelta(days=1)
start_date = specific_date.replace(hour=0, minute=0, second=0, microsecond=0).isoformat()
end_date = specific_date.replace(hour=23, minute=59, second=59, microsecond=999999).isoformat()
# Set the API endpoint URL
url = f"https://api.hubapi.com/contacts/v1/lists/{list_id}/contacts/all"
# Set the request parameters
params = {
“hapikey”: api_key,
“start”: start_date,
“end”: end_date
}
# Send the API request
response = requests.get(url, params=params)
# Check if the request was successful
if response.status_code == 200:
# Parse the response data
data = response.json()
# Extract the list of contacts from the response
contacts = data.get(“contacts”, [])
# Print the list of contacts
for contact in contacts:
print(contact)
else:
print(f"Error occurred during API request: {response.status_code} {response.text}")