Old API key as query string method is running

I have an API integration where using post method I am sending data to https://api.hubapi.com/contacts/v1/contact/email/<email>/profile api.
Now I tried to send data to this API using POST menthod using new private app access token method in curl header. But is failed.
But when I switch back to old https://api.hubapi.com/contacts/v1/contact/email<email>/profile?hapikey=<api-key> method then data gets synced as it was previously.
Is it the right thing to do?

Hey @AMUKHERJEE1010 ,

thank you for reaching out to the community.

I definitely recommend using the access token of a private app from now on. Even thought the API Key might still work for you now, I don’t expect it to work anytime soon.

Would you mind sharing with us what error message you get. You should get one in the console or maybe have look into the details of your logs within the Private App.

Here is where you find these.

Cheers,

Chriso

Hey @AMUKHERJEE1010,

As of November 30th HubSpot has sunset the use of API keys. I’m not sure why you are still able to make requests using one but I wouldn’t rely on this as a stable approach moving forward. You should be using the private app access token.

If your request is failing using an access token it’s likely that you’ve included it incorrectly. It should be passed as a header in the request. Are you getting any error messages/response codes back from HubSpot, if you are can you please share?

Also, I’d recommend using the newer CRM Contact APIs instead of the legacy v1 endpoints. Specifically the PATCH /crm/v3/objects/contacts/{contactId} endpoint. You can update contacts using email address as per the below:

$headers = [
‘Content-Type: application/json’,
‘Authorization: Bearer <access-token>’,
];

$url = ‘https://api.hubapi.com/contacts/v1/contact/email/\/profile’;
$arr = array(
‘properties’ => array(
array(
‘property’ => ‘pls_calculator_annual_results’,
‘value’ => <VALUE>
),
array(
‘property’ => ‘pls_calculator_fortnight_results’,
‘value’ => <VALUE>
),
array(
‘property’ => ‘pls_calculator_payment_years’,
‘value’ => <VALUE>
),
array(
‘property’ => ‘pls_calculator_equity_remaining_after_20_years’,
‘value’ => <VALUE>
)
)
);
$post_json = json_encode($arr);

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
curl_close($ch);

----- This was my code which didn’t work. That’s why I returned back to old API key as query string method

Hey @AMUKHERJEE1010 what error message (if any) are you getting back? Also make sure you’ve correctly assigned the crm.objects.contacts.write scope to your access token/private app.