API error

Hello,

We’re testing the ‘Delete a contact’ API. (https://legacydocs.hubspot.com/docs/methods/contacts/delete_contact)

But I got a 405 error and its error message is ‘Method Not Allowed’.

Do you know what is the reason?

I have attached the code we tested.

Please see the below image!


Json Code

I think it might be an API version issue, so we’re testing it with the V3 API.

When we send the URL directly, we could delete contacts in HubSpot.

However, when applied as a source, we had a return message like the attached image and we could not delete contacts.

If there is anyone to have a solution, please let me know the way!!

Best Regards,

Eunjin

Thank you for your post @jini .

@dannio and @MichaelC , would you be able to share your advice for Eunjin?

Hello @jini,

As mentioned in the documentation the type of request should be “DELETE”, and that’s why the error response of the method is not allowed.

Please add this line in your code and it should work - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “DELETE”);

and please delete the attachment example, as it has your hapikey or you can update your API key in HubSpot.

Hope this solves the issue!

Regards,

Hi @himanshurauthan,

Thanks for your kind solution!

By adding the code you shared, we were able to delete the contacts successfully.

Regards,

Hi @jini ,
You must be using wrong api method .Please use “Delete” method to hit the url successffully. add your vid and hapikey in the below mentioned curl code : $curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => ‘https://api.hubapi.com/contacts/v1/contact/vid/61571?hapikey=demo’,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => ‘’,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => ‘DELETE’,
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

Hope this helps!

If we were able to answer your query, kindly help the community by marking it as a solution.
Thanks and Regards.