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 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)

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"

Thank you Wendy, it worked !!