We're excited to announce that we're launching the second installment of Dataiku Product Days Register Now

python: unable to post data to Hubspot from DKU

apogee211
Level 1
python: unable to post data to Hubspot from DKU

Hello,

I'm attempting to upload a dataset to Hubspot from Dataiku using Python. The procedure runs fine in DKU but fails to upload data into Hubspot.  Note - this code does post to Hubspot when run from my local computer. I'm wondering what is DKU doing that is different from my local version when posting data to an external site?

beg_url = 'https://api.hubapi.com/crm/v3/imports?'
end_url = 'hapikey={}'.format(API_key)
post_url = beg_url+end_url

data = {
"name": "my_import",
"files": [
{
"fileName": "Combined_HS_Metrics_test.csv",
"fileFormat":"CSV",
"fileImportPage": {
"hasHeader": True,
"columnMappings": [

{
"ignored":False,
"columnName":"company_id",
"idColumnType":"HUBSPOT_OBJECT_ID",
"propertyName":"company id",
"foreignKeyType":None,
"columnObjectType":"COMPANY",
"associationIdentifierColumn":False
}

]

}
}
]
}

files = {
'importRequest': (None, json.dumps(data), 'multipart/form-data'),

'files': "Combined_HS_Metrics_test.csv"
}
response = requests.put(post_url, files=files)

0 Kudos
4 Replies
HenriC
Dataiker
Dataiker

Hi @apogee211 !

To be sure I understand the problem, you manage to upload a dataset to Hubspot by executing this python script in local, but when you run it from Dataiku, it executes successfully without error but does not upload any data at the end fo the day. Am I right ?

Have a nice day,

Henri

0 Kudos
apogee211
Level 1
Author

Hi Henri,

Yes, that's exactly correct.  

Thanks! 

John

0 Kudos
HenriC
Dataiker
Dataiker

Thanks for the confirmation ! It is indeed very strange, could you please check that the response has a success code ? Meaning adding the following code at the end of your Python file :

print(response)
print(response.content)

It wouldn't make sense if the code was the same from your local env and DSS as the response is sent back by Hubpot, so if it sends a success code, it means that it has interpreted the put request as successful.

0 Kudos
apogee211
Level 1
Author

Thanks, I do have a response code (see below) which is returning no data.  Initially,  I was using a "requests.request" function which was returning "bad request 400".  However, I switched to requests.put but this is returning an empty string. 

#initially#   response = requests.request("POST", post_url, files=files)
#current#   response = requests.put(post_url, files=files)

#feedback 

Hubspot_Upload_status = dataiku.Dataset("Hubspot_Upload_status")
the_row = {}
the_row["information"] = response.text
with Hubspot_Upload_status.get_writer() as writer:
writer.write_row_dict(the_row)

0 Kudos
A banner prompting to get Dataiku DSS