CRM Imports Endpoint

SOLVE
Highlighted
New Contributor

Hi, can someone help me with the sample payload/body/data part for this POST request? (https://developers.hubspot.com/docs-beta/crm/imports)

Apparently we can use Excel or CSV source file but i couldn't manage to define it

import requests

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

querystring = {"hapikey":"xxxx-xxxx"}

payload = "{\"importRequest\":\"datetime\"}"
headers = {
    'accept': "application/json",
    'content-type': "multipart/form-data"
    }

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

print(response.text) 

 Thanks

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
HubSpot Moderator

Hi, @etezisci.

 

Our documentation is still a work in progress, but the following worked for me:

 

var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.hubapi.com/crm/v3/imports/?hapikey=xxxx-xxxx',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
formData: {
'files': {
'value': fs.createReadStream('/Users/itakushi/Documents/API_Import_1.csv'),
'options': {
'filename': 'API_Import_1.csv',
'contentType': null
}
},
'importRequest': '{"name":"API_Import_1","files":[{"fileName":"API_Import_1.csv","fileImportPage":{"hasHeader":true,"columnMappings":[{"ignored":false,"columnName":"email","idColumnType":"HUBSPOT_ALTERNATE_ID","propertyName":"email","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false},{"ignored":false,"columnName":"firstname","idColumnType":null,"propertyName":"firstname","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false},{"ignored":false,"columnName":"lastname","idColumnType":null,"propertyName":"lastname","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false}]}}]}'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});

Here's a better look at the importRequest object:

{
  "name": "API_Import_1",
  "files": [
    {
      "fileName": "API_Import_1.csv",
      "fileImportPage": {
        "hasHeader": true,
        "columnMappings": [
          {
            "ignored": false,
            "columnName": "email",
            "idColumnType": "HUBSPOT_ALTERNATE_ID",
            "propertyName": "email",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          },
          {
            "ignored": false,
            "columnName": "firstname",
            "idColumnType": null,
            "propertyName": "firstname",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          },
          {
            "ignored": false,
            "columnName": "lastname",
            "idColumnType": null,
            "propertyName": "lastname",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          }
        ]
      }
    }
  ]
}

My CSV file, API_Import_1.csv, had three columns. In order: "email" mapping to email, "firstname" mapping to firstname, and "lastname" mapping to lastname.

 

Here are screenshots of the draft documentation for the other fields:

Screen Shot 2020-01-27 at 1.36.16 PM.pngRequired ParametersScreen Shot 2020-01-27 at 1.36.26 PM.pngOptional Parameters

I hope this helps others while we work to publish formal documentation on this endpoint.

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
2 Replies 2
HubSpot Moderator

Hi, @etezisci.

 

Our documentation is still a work in progress, but the following worked for me:

 

var request = require('request');
var fs = require('fs');
var options = {
'method': 'POST',
'url': 'https://api.hubapi.com/crm/v3/imports/?hapikey=xxxx-xxxx',
'headers': {
'Content-Type': 'application/x-www-form-urlencoded'
},
formData: {
'files': {
'value': fs.createReadStream('/Users/itakushi/Documents/API_Import_1.csv'),
'options': {
'filename': 'API_Import_1.csv',
'contentType': null
}
},
'importRequest': '{"name":"API_Import_1","files":[{"fileName":"API_Import_1.csv","fileImportPage":{"hasHeader":true,"columnMappings":[{"ignored":false,"columnName":"email","idColumnType":"HUBSPOT_ALTERNATE_ID","propertyName":"email","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false},{"ignored":false,"columnName":"firstname","idColumnType":null,"propertyName":"firstname","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false},{"ignored":false,"columnName":"lastname","idColumnType":null,"propertyName":"lastname","foreignKeyType":null,"columnObjectType":"CONTACT","associationIdentifierColumn":false}]}}]}'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});

Here's a better look at the importRequest object:

{
  "name": "API_Import_1",
  "files": [
    {
      "fileName": "API_Import_1.csv",
      "fileImportPage": {
        "hasHeader": true,
        "columnMappings": [
          {
            "ignored": false,
            "columnName": "email",
            "idColumnType": "HUBSPOT_ALTERNATE_ID",
            "propertyName": "email",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          },
          {
            "ignored": false,
            "columnName": "firstname",
            "idColumnType": null,
            "propertyName": "firstname",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          },
          {
            "ignored": false,
            "columnName": "lastname",
            "idColumnType": null,
            "propertyName": "lastname",
            "foreignKeyType": null,
            "columnObjectType": "CONTACT",
            "associationIdentifierColumn": false
          }
        ]
      }
    }
  ]
}

My CSV file, API_Import_1.csv, had three columns. In order: "email" mapping to email, "firstname" mapping to firstname, and "lastname" mapping to lastname.

 

Here are screenshots of the draft documentation for the other fields:

Screen Shot 2020-01-27 at 1.36.16 PM.pngRequired ParametersScreen Shot 2020-01-27 at 1.36.26 PM.pngOptional Parameters

I hope this helps others while we work to publish formal documentation on this endpoint.

Isaac Takushi

HubSpot Developer Support
Reply
0 Upvotes
New Contributor

Thank you Isaac! It worked for me too.