APIs & Integrations

EMCC
Mitglied

apikey doesn't exist

Hello,

I am trying to implement the contact creation API using a html form to capture leads. I have created the API key by creating the private app in my hubspot account. But when i am using that particular API key to make the request API call it says api key does not exist. Please kindly help me with this.

Can anyone help me with this?

MY ENDPOINT: 

$endpoint = 'https://api.hubapi.com/contacts/v1/contact?hapikey=XXX-XXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';

Error:

curl Errors: Status code: 401 Response: {"status":"error","message":"This hapikey doesn't exist.","correlationId":"c8ba6603-59a8-43f7-bbda-8330085593af"}

0 Upvotes
1 Antwort
Jaycee_Lewis
Community-Manager/-in
Community-Manager/-in

apikey doesn't exist

Hey, @EMCC 👋 It looks like your request is combining both methods of Authorization. If you are using a private app, then your request URL will not include the 

?hapikey=XXX-XXX-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX';

part.

 

You need to include 

--header 'authorization: Bearer YOUR_ACCESS_TOKEN' \

 in your header.

 

Here's a quick example using cURL:

Request

 

curl --request POST \
  --url https://api.hubapi.com/crm/v3/objects/contacts \
  --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
  --header 'content-type: application/json' \
  --data '{
  "properties": {
    "company": "Cat Pizza",
    "email": "sebastian@catsrule.xyz",
    "firstname": "Sebastian",
    "lastname": "Lewis",
    "phone": "(805)-457-4992",
    "website": "surferboypizza.xyz"
  }
}'

 

Response

 

HTTP 201

{
  "id": "601",
  "properties": {
    "company": "Cat Pizza",
    "createdate": "2022-08-18T20:14:18.110Z",
    "email": "sebastian@catsrule.xyz",
    "firstname": "Sebastian",
    "hs_all_contact_vids": "601",
    "hs_calculated_phone_number": "+18054574992",
    "hs_calculated_phone_number_country_code": "US",
    "hs_email_domain": "catsrule.xyz",
    "hs_is_contact": "true",
    "hs_is_unworked": "true",
    "hs_marketable_status": "false",
    "hs_marketable_until_renewal": "false",
    "hs_object_id": "601",
    "hs_pipeline": "contacts-lifecycle-pipeline",
    "hs_searchable_calculated_phone_number": "8054574992",
    "lastmodifieddate": "2022-08-18T20:14:18.110Z",
    "lastname": "Lewis",
    "phone": "(805)-457-4992",
    "website": "http://surferboypizza.xyz"
  },
  "createdAt": "2022-08-18T20:14:18.110Z",
  "updatedAt": "2022-08-18T20:14:18.110Z",
  "archived": false
}

 

 

PHP example from documentation

Request

 

<?php
use HubSpot\Factory;
use HubSpot\Client\Crm\Contacts\ApiException;

$client = Factory::createWithAccessToken("YOUR_ACCESS_TOKEN");

$properties = [
    "company" => "Cat Pizza",
    "email" => "sebastian@catsrule.xyz",
    "firstname" => "Sebastian",
    "lastname" => "Lewis",
    "phone" => "(805)-457-4992",
    "website" => "surferboypizza.xyz"
];
$SimplePublicObjectInput = new SimplePublicObjectInput(['properties' => $properties]);
try {
    $apiResponse = $client->crm()->contacts()->basicApi()->create($SimplePublicObjectInput);
    var_dump($apiResponse);
} catch (ApiException $e) {
    echo "Exception when calling basic_api->create: ", $e->getMessage();
}

 

 

I hope this helps get you moving forward! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes