Hello, I am trying to write a python script to automate a weekly file upload. The file is in my google drive, containing 4 columns, with email address in the 2nd column. I’ve been referencing the document Accounts Dashboard | HubSpot
but getting a 400 error returned. Any help appreciated as I’m not a developer but asked to do this.
--------------------------------------------------------
import requests
import json
url = “https://api.hubapi.com/crm/v3/imports?hapikey=60***”
data = {
“name”: “score_react”,
“files”: [
{
"fileName": "score\_react.csv",
"fileFormat": "CSV",
"fileImportPage": {
"hasHeader": True,
"columnMappings": \[
{
"ignored": True,
},
{
"ignored": False,
"columnName": "email",
"idColumnType": None,
"propertyName": "email",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifiedColumn": False
},
{
"ignored": False,
"columnName": "reactivation\_score",
"idColumnType": None,
"propertyName": "reactivation\_score",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifiedColumn": False
},
{
"ignored": False,
"columnName": "reactivation\_category",
"idColumnType": None,
"propertyName": "reactivation\_category",
"foreignKeyType": None,
"columnObjectType": "CONTACT",
"associationIdentifiedColumn": False
}
]
}
}
]}
datastring = json.dumps(data)
payload = {“importRequest”: datastring}
files = [
(‘files’, open(‘/drive/My Drive/score_react.csv’,‘r’))
]
response = requests.request(“POST”, url, data = payload, files = files)
print(response.text.encode(‘utf8’))
print(response.status_code)