APIs & Integrations

Ron_at_BRCC
メンバー

Help with Python code to upload file from Google drive

解決

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 いいね!
1件の承認済みベストアンサー
WendyGoh
解決策
HubSpot Employee
HubSpot Employee

Help with Python code to upload file from Google drive

解決

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 いいね!
2件の返信
WendyGoh
解決策
HubSpot Employee
HubSpot Employee

Help with Python code to upload file from Google drive

解決

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 いいね!
Ron_at_BRCC
メンバー

Help with Python code to upload file from Google drive

解決

Thank you Wendy, it worked !!

0 いいね!