adding contact to list

Hi,

pls check the bwlow code what we are using for to adda contact to a list(static).

// 52366813746765 is the contact id

$properties = [

“52366813746765”

];

$params = json_encode(

[

‘data’ => $properties

]

);

$curl = curl_init();

// 14912312 is static list id

curl_setopt_array($curl, array(

CURLOPT_URL => “https://api.hubapi.com/crm/v3/lists/14912312/memberships/add”,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => “”,

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 30,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => “POST”,

CURLOPT_POSTFIELDS => $params,

CURLOPT_HTTPHEADER => array(

“Authorization: Bearer xxxxxxxxxxxxxxxxxxxxx”,

“accept: application/json”,

“content-type: application/json”

),

));

$response = curl_exec($curl);

$err = curl_error($curl);

curl_close($curl);

i am getting empty response pls check once.

Hi @Prakashreddy

Hi, Here’s the curl command that should help you:

curl --request PUT \
 --url https://api.hubapi.com/crm/v3/lists/list_id/memberships/add \
 --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
 --header 'content-type: application/json' \
 --data '[
 "contact_id_1",
 "contact_id_2",
 "contact_id_3"
]'

I hope this will help you out. Please mark it as Solution Accepted and upvote to help another Community member.
Thanks!

ITS NOT WRKING pls check below.

$curl = curl_init();

curl_setopt_array($curl, array(

CURLOPT_URL => “https://api.hubapi.com/crm/v3/lists/149/memberships/add”,

CURLOPT_RETURNTRANSFER => true,

CURLOPT_ENCODING => “”,

CURLOPT_MAXREDIRS => 10,

CURLOPT_TIMEOUT => 30,

CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,

CURLOPT_CUSTOMREQUEST => “PUT”,

CURLOPT_POSTFIELDS => ‘[5236681374]’,

CURLOPT_HTTPHEADER => array(

“Authorization: Bearer xxxxxxxxxxxxx”,

“accept: application/json”,

“content-type: application/json”

),

));

$response = curl_exec($curl);

$err = curl_error($curl);

curl_close($curl);

echo “<pre>”;

print_r(json_decode($response));

die();

//response

stdClass Object
(
 [status] => error
 [message] => List does not exist with ID 149.
 [correlationId] => 9b7d3293-bcc2-4bd1-8488-5290216cc972
 [context] => stdClass Object
 (
 [listId] => Array
 (
 [0] => 149
 )

 )

 [category] => OBJECT_NOT_FOUND
 [subCategory] => ListError.LIST_ID_DOES_NOT_EXIST
)

where as i retrived all lists using v1 api, and i m sendig the 149 list id object.in the response u can see portal id also

[21] => stdClass Object
(
[portalId] => 3405807
[listId] => 149
[createdAt] => 1710938629968
[updatedAt] => 1710938630058
[name] => Test
[listType] => STATIC
[authorId] => 44492467
[filters] => Array
(
)

[metaData] => stdClass Object
(
[size] => 0
[lastSizeChangeAt] => 1710938659441
[processing] => DONE
[lastProcessingStateChangeAt] => 1710938630879
[error] =>
[listReferencesCount] =>
[parentFolderId] =>
)

[archived] =>
[teamIds] => Array
(
)

[ilsFilterBranch] =>
[readOnly] =>
[internal] =>
[limitExempt] =>
[dynamic] =>
)

not only 149 list id i tried with different ids for every thing same response

our requiremnet is we have to craete a list first we willimport the contacts in that list after that when ever new user added , updated from our webappilcation ,this changes we want to post it to hubspot using api.

i have observed we can do this process for the list type manual or snapshot not for dynamic.

can u pls advise us what are the things we have to keep in mind when creating a list in hubspot so that we can do the following tasks

adding contacts to list using api

updating contact of a list using api

deleting contact from a list using api.

as per the api we have to first create a contact and need to send contact id to the list api along with list id, is this not possible at the time of creating contact send list id also?

Thank you.