phppostmanguzzlehubspothubspot-api

What's a correct example of Hubspot API CSV import request?


I'm trying to use the Import API to import some contacts.

I'm using an over-simplified version of their Sample CSV file which looks like this:

First Name Last Name Email Address
Lorelai Gilmore lorelai@thedragonfly.com
Leslie Knope leslie@pawneeparks.com
Eleanor Shellstrop eleanor@thegoodplace.com

I've tried several request variations using Postman or Guzzle (my implementation is written in PHP). Every time I get a 400 error: POST https://api.hubapi.com/crm/v3/imports/ resulted in a 400 Bad Request response

Here is a simplified version of the request:

<?php
$client = new Client();
$headers = [
  'Content-Type' => 'multipart/form-data',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer xxx-xxx-xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx'
];
$options = [
  'multipart' => [
    [
      'name' => 'files',
      'contents' => Utils::tryFopen('/path/to/file/HubSpot example - Contacts import file.csv', 'r'),
      'filename' => '/path/to/file/HubSpot example - Contacts import file.csv'
    ],
    [
      'name' => 'importRequest',
      'contents' => '{"name":"customers_import","files":[{"fileName":"/path/to/file/HubSpot example - Contacts import file.csv","fileFormat":"CSV","fileImportPage":{"hasHeader":true,"columnMappings":[{"ignored":false,"columnName":"First Name","idColumnType":null,"propertyName":"firstname","columnObjectType":"CONTACT"},{"ignored":false,"columnName":"Last Name","idColumnType":null,"propertyName":"lastname","columnObjectType":"CONTACT"},{"ignored":false,"columnName":"Email Address","idColumnType":null,"propertyName":"email","columnObjectType":"CONTACT"}]}}]}'
    ]
]];
$request = new Request('POST', 'https://api.hubapi.com/crm/v3/imports/', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();

Some other things I've tried:

//...
"importOperations" => [
     "0-1" => "CREATE"
],
"dateFormat" => "DAY_MONTH_YEAR",
"marketableContactImport" => true,
//...

I'm looking for a simple sample request that just works.


Solution

  • The problem was the fileName property inside importRequest JSON content. That value should not include the path.