APIs & Integrations

Ron_at_BRCC
Member

Help with Python code to upload file from Google drive

SOLVE

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 https://developers.hubspot.com/docs/api/crm/imports

but getting a 400 error returned.  Any help appreciated as I'm not a developer but asked to do this.

--------------------------------------------------------

 


import requests
import json


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)
0 Upvotes
1 Accepted solution
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Help with Python code to upload file from Google drive

SOLVE

Hey @Ron_at_BRCC,

 

Could you ensure two things here:

 

1. On the data portion formatting, could you ensure that the order is the same as how the data are listed on the csv file?

2. Additionally, any columns that you'd like to skip the mapping on, could you add this in: 

"ignored": True,
"columnName": "InsertColumnNameToBeSkippedHere"

 

View solution in original post

0 Upvotes
2 Replies 2
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

Help with Python code to upload file from Google drive

SOLVE

Hey @Ron_at_BRCC,

 

Could you ensure two things here:

 

1. On the data portion formatting, could you ensure that the order is the same as how the data are listed on the csv file?

2. Additionally, any columns that you'd like to skip the mapping on, could you add this in: 

"ignored": True,
"columnName": "InsertColumnNameToBeSkippedHere"

 

0 Upvotes
Ron_at_BRCC
Member

Help with Python code to upload file from Google drive

SOLVE

Thank you Wendy, it worked !!

0 Upvotes