# API Contact Import Error (Error 400 Bad Request)

**URL:** <https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244>\
**Category:** APIs & Integrations\
**Tags:** python, contacts\
**Created:** [October 17, 2022, 8:31am UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244 "2022-10-17T08:31:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danjelito](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@danjelito](https://community.hubspot.com/u/danjelito)\
**Post date:** [October 17, 2022, 8:31am UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244/1 "2022-10-17T08:31:41Z")

</div>

Hi everyone, I’m trying to use API to do the following thing: import contacts from CSV file in my local disk. But, I get Error 400 Bad Request and I don’t know why. I checked everything but it seems like everything is correct.

Here is my code:

```lia-code-sample
date_subdir= "2022-10-17" #subdirectory in which my file is located
filename= "2022-09-17 to 2022-10-16 match.csv"
parent_dir= r"H:\My Drive\1. Digital Marketing\sync hubspot erwin master"

from pathlib import Path
import requests
import json
import os

url = "https://api.hubapi.com/crm/v3/imports"

ACCESS_TOKEN = "my private app access token";

headers = {
 'content-type': 'multipart/form-data',
 'authorization': 'Bearer %s' % ACCESS_TOKEN
}

data = {
 "name": filename.split('.')[0], #returns 2022-09-17 to 2022-10-16 match, the import name i want
 "files": [
 {
 "fileName": filename, #returns 2022-09-17 to 2022-10-16 match.csv
 "fileFormat": "CSV",
 # "dateFormat": "DAY_MONTH_YEAR", #there's no date in my file though
 "fileImportPage": {
 "hasHeader": True,
 "columnMappings": [
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Record ID",
 "propertyName": "hs_object_id",
 "idColumnType": "HUBSPOT_OBJECT_ID"
 },
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Phone Number",
 "propertyName": "phone",
 "idColumnType": False
 },
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Email",
 "propertyName": "email",
 "idColumnType": "HUBSPOT_ALTERNATE_ID"
 },
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Lifecycle Stage",
 "propertyName": "lifecyclestage",
 "idColumnType": False
 },
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Learning Preference", #a custom property i made for my use
 "propertyName": "learning_preference",
 "idColumnType": False
 },
 {
 "columnObjectTypeId": "0-1",
 "columnName": "Is TMK Call?",#a custom property i made for my use
 "propertyName": "is_tmk_call_",
 "idColumnType": False
 }
 ]
 }
 }
 ]
}

datastring = json.dumps(data)

payload = {"importRequest": datastring}

absolute_file_path = Path(parent_dir, date_subdir, filename) #returns WindowsPath('H:/My Drive/1. Digital Marketing/sync hubspot erwin master/2022-10-17/2022-09-17 to 2022-10-16 match.csv'), which is correct

files = [
 ('files', open(absolute_file_path, 'rb'))
]
print(files)

response = requests.request("POST", url, data=payload, files=files, headers=headers)

print(response.text.encode('utf8'))
print(response.status_code)

the error i get:
[('files', <_io.BufferedReader name='H:\\My Drive\\1. Digital Marketing\\sync hubspot erwin master\\2022-10-17\\2022-09-17 to 2022-10-16 match.csv'>)]
Error 400 Bad Request

```

Any idea? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [October 17, 2022, 10:27pm UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244/2 "2022-10-17T22:27:30Z")

</div>

Hi, @danjelito 👋 Have you tried using Postman as shown in the example here? — [Start an import](https://developers.hubspot.com/docs/api/crm/imports#:~:text=in%20HubSpot.-,Start%20an%20import,-You%20can%20start)

It may help us root out any additional issues.

Best,

Jaycee

---

<div class="post-metadata">

**Author:** ![danjelito](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@danjelito](https://community.hubspot.com/u/danjelito)\
**Post date:** [October 18, 2022, 2:44am UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244/3 "2022-10-18T02:44:32Z")

</div>

Hi [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074) , not yet, currently I’m trying to use Python from my local computer to run above script. Do I have to use Postman to run this?

---

<div class="post-metadata">

**Author:** ![Anya23](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Anya23](https://community.hubspot.com/u/Anya23)\
**Post date:** [March 27, 2025, 2:39pm UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244/4 "2025-03-27T14:39:01Z")

</div>

This is an old post. Did you ever get it worked out? Usually a 400 error includes Content that contains an error message. Are you able to see that with this error?

---

<div class="post-metadata">

**Author:** ![SSun7](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@SSun7](https://community.hubspot.com/u/SSun7)\
**Post date:** [May 5, 2025, 6:06pm UTC](https://community.hubspot.com/t/api-contact-import-error-error-400-bad-request/67244/5 "2025-05-05T18:06:23Z")

</div>

Hi Anya, I’m encountering similar issues, and I’m wondering if you’ve figured this out? Thanks!
