Using API to get data from the day before
Hello
I would like to use an API to get data which has been updated a day before. This is my code but it seems not to be working:
import requests
import json
from datetime import datetime, timedelta
yesterday_start = (datetime.now() - timedelta(100)).replace(hour=0, minute=0, second=0, microsecond=0)
yesterday_end = (datetime.now() - timedelta(1)).replace(hour=23, minute=59, second=59, microsecond=999999)
yesterday_start_str = yesterday_start.strftime("%Y-%m-%dT%H:%M:%SZ")
yesterday_end_str = yesterday_end.strftime("%Y-%m-%dT%H:%M:%SZ")
user_key = xy
url = "https://api.crunchbase.com/api/v4/searches/funding_rounds?user_key=" + user_key
payload = {
"field_ids":[
"identifier",
"uuid",
"updated_at"
],
"query":[
{
"type":"predicate",
"field_id":"updated_at",
"operator_id":"gte",
"values":["2024-07-23T00:00:00Z"]
},
{
"type":"predicate",
"field_id":"updated_at",
"operator_id":"lte",
"values":["2024-04-23T23:59:59Z"]
}
]
}
headers = {
"Content-Type":"application/json"
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
if response.status_code == 200:
print("Success!")
data = response.json()
else:
print("Failed to retrieve data")
print("Status Code:", response.status_code)
print("Response:", response.text)
data = None
Would appreciate if somebody could help.
Kindly,
benjamin
Comments
1 comment
Hi Benjamin Klavins - a member of our team will reach out to assist.
Please sign in to leave a comment.