APIs & Integrations

etezisci
Teilnehmer/-in

CRM Imports Endpoint

lösung

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

0 Upvotes
1 Akzeptierte Lösung
IsaacTakushi
Lösung
HubSpot Employee
HubSpot Employee

CRM Imports Endpoint

lösung

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:

Required ParametersRequired ParametersOptional ParametersOptional Parameters

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

Isaac Takushi

Associate Certification Manager

Lösung in ursprünglichem Beitrag anzeigen

0 Upvotes
2 Antworten
IsaacTakushi
Lösung
HubSpot Employee
HubSpot Employee

CRM Imports Endpoint

lösung

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:

Required ParametersRequired ParametersOptional ParametersOptional Parameters

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

Isaac Takushi

Associate Certification Manager
0 Upvotes
etezisci
Teilnehmer/-in

CRM Imports Endpoint

lösung

Thank you Isaac! It worked for me too.