Hi there,
I am trying to do CRM Bulk Import, for that, I am using “hubspot/api-client” and I am authenticating with “api-key”.
But I am always getting “400 Bad Request” as a response.
FYI, this script is working if I use OAuth instead of API key but I want to use API Key
I couldn’t figure out why it’s not working with the API key, any help would be highly appreciated.
Here goes my code:
if(file_exists('src/files/formatted/contact.csv')) { try { $hubSpot = Factory::createWithApiKey($this->key); $request = json_encode([ "name" => "Import (Contact)", "files" => [ [ "fileName" => "contact", "fileImportPage" => [ "hasHeader" => true, "columnMappings" => [ [ "columnName" => "First Name", "propertyName" => "firstname", "columnObjectType" => "CONTACT", ], [ "columnName" => "Contact Email Domain", "propertyName" => "contact_email_domain", "columnObjectType" => "CONTACT", ], [ "columnName" => "Email", "propertyName" => "email", "columnObjectType" => "CONTACT", ], [ "columnName" => "Company name", "propertyName" => "company", "columnObjectType" => "CONTACT", ], [ "columnName" => "Country/Region", "propertyName" => "country", "columnObjectType" => "CONTACT", ], [ "columnName" => "Full Name", "propertyName" => "full_name", "columnObjectType" => "CONTACT", ], [ "columnName" => "Phone number", "propertyName" => "phone", "columnObjectType" => "CONTACT", ], ], ], ], ], ]); $hubSpot->crm()->imports()->coreApi()->create('src/files/formatted/contact.csv', $request); @unlink('src/files/formatted/contact.csv'); } catch (ApiException $e) { echo "Exception when calling core_api->create: ", $e->getMessage(); }}
## contact.csv
firstname,contact_email_domain,email,company,country,full_name,phoneTest,test.com,test@test.com,Test,GB,Test Test,0123456