APIs & Integrations

Prakashreddy
Member

removing contact from a list

Hi,

 

i have a list with name "Verdict - Membership and Subscription Data" with list id 17945.

 

i am trying to delist a contact from thelist using api.. below is the code.

 

 

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.hubapi.com/crm/v3/lists/".$list_id."/memberships/remove",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS =>"[".$contact_id."]",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$hubspot_auth,
"accept: application/json",
"content-type: application/json"
),
));

 

i m reciving the below error. do we need any permissions to perform this action pls helpme

{"status":"error","message":"List does not exist with ID 17945.","correlationId":"fa79155b-974f-4c6b-9ae8-97af40ac9bb3","context":{"listId":["17945"]},"category":"OBJECT_NOT_FOUND","subCategory":"ListError.LIST_ID_DOES_NOT_EXIST"}

 

0 Upvotes
4 Replies 4
Jaycee_Lewis
Community Manager
Community Manager

removing contact from a list

Hey, @Prakashreddy 👋 You are correct. Active (dynamic) lists use filters to include or exclude objects. You cannot delete contacts, for example, from an active list. 

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
james-portant
Contributor

removing contact from a list

Hi @Prakashreddy,

 

Hiow's it going?

Here are a few steps to troubleshoot your current approach:

  1. Verify List ID: Ensure that the list ID 17945 is correct. You can do this by checking the list in your HubSpot account.

  2. API Endpoint and Payload: The API endpoint and the payload need to be correctly formatted. Specifically, the contact ID should be in a JSON array format.

  3. Permissions: Ensure that your HubSpot API token has the necessary permissions to modify lists and contacts.

Here is an updated version of your code:

<?php

$list_id = "17945"; // Ensure this is the correct list ID
$contact_id = "CONTACT_ID_HERE"; // Replace with the actual contact ID
$hubspot_auth = "YOUR_HUBSPOT_AUTH_TOKEN"; // Your HubSpot API token

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.hubapi.com/contacts/v1/lists/$list_id/remove",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode(array("vids" => array($contact_id))),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer $hubspot_auth",
"accept: application/json",
"content-type: application/json"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>

 
 
  • Endpoint: Use /contacts/v1/lists/:list_id/remove for the removal action.
  • Payload: The contact ID should be sent in a JSON format as an array under the key vids.
  • Method: Use POST instead of PUT for this specific action.

 

Hopefully this helps track down the issue.

Good luck,
James - CEO @ Portant

Portant App for HubSpot: https://ecosystem.hubspot.com/marketplace/apps/sales/sales-enablement/portant-hubspot-google-docs-in...

 

0 Upvotes
Prakashreddy
Member

removing contact from a list

i executed the code what u gave i got below response.

 

{"status":"error","message":"Api[name=inbounddb.listseg, httpMethod=POST, subPath=/inbounddb-lists/v1/static-lists/validated, correlationId=717ff9b3-e3df-4311-be95-5792b9292e03] Failed to process your request. Error code was '400'. Error message was:\n{\"status\":\"error\",\"message\":\"List 27808 has processing type DYNAMIC which is not allowed to be used in manual membership update processes.\",\"correlationId\":\"717ff9b3-e3df-4311-be95-5792b9292e03\"}","correlationId":"717ff9b3-e3df-4311-be95-5792b9292e03"}{"status":"error","message":"Api[name=inbounddb.listseg, httpMethod=POST, subPath=/inbounddb-lists/v1/static-lists/validated, correlationId=717ff9b3-e3df-4311-be95-5792b9292e03] Failed to process your request. Error code was '400'. Error message was:\n{\"status\":\"error\",\"message\":\"List 27808 has processing type DYNAMIC which is not allowed to be used in manual membership update processes.\",\"correlationId\":\"717ff9b3-e3df-4311-be95-5792b9292e03\"}","correlationId":"717ff9b3-e3df-4311-be95-5792b9292e03"}

 

my question is why in the response it mentioned  List 27808

my list id is 17945 and i  passed 17945 to the request.. is 27808 internal some reference number for that list id

0 Upvotes
Prakashreddy
Member

removing contact from a list

Thank you for your response.

 

i found 17945 list id type is dynamic..

 

can we remove contact from a dynamic list using api.

 

in one article i found we cann not remove contacts from a dynamic list..

 

pls confirm

 

Thank you 

0 Upvotes