I am using the HubSpot API to export a view using the Export API. I am able to start an export by making a POST request to this endpoint '/crm/v3/exports/export/async'. From there, I want to get that data into a dataframe in python. According to the documentation, thats done by making a GET request to '/crm/v3/exports/export/async/tasks/{taskId}/status', passing in the taskid returned after starting the export.
Everything is working for me up to this point, but I am struggling to read the contents of the file. Does it need to be decoded? Are there any examples of how to do this?
import requests
import pandas as pd
# Set the API endpoint
endpoint = "https://api.hubspot.com/crm/v3/exports/export/async/tasks/{taskId}/status"
# Get the task ID
task_id = "1234567890"
# Make a GET request to the API endpoint
response = requests.get(endpoint, params={"taskId": task_id})
# Check the response status code
if response.status_code == 200:
# Get the file contents
file_contents = response.content
# Decode the file contents
file_contents = file_contents.decode("utf-8")
# Create a Pandas DataFrame from the file contents
df = pd.read_csv(file_contents)
# Print the DataFrame
print(df)
This code will first set the API endpoint and get the task ID. Then, it will make a GET request to the API endpoint and check the response status code. If the response status code is 200, the code will get the file contents, decode them, and create a Pandas DataFrame from them. Finally, the code will print the DataFrame. The file contents may be encoded in a different format, such as UTF-16 or UTF-32. If this is the case, you will need to specify the correct encoding when decoding the file contents. For example, to decode the file contents as UTF-16, you would use the following code.
the response is just a status, and link where the file can be downloaded from. This is also confirmed in the API documentation as the expected behavior. Here is the response :
So, my question is then, how can I programatically use that link to retrieve the data?