# adding contact to list

**URL:** <https://community.hubspot.com/t/adding-contact-to-list/103065>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [March 21, 2024, 8:48am UTC](https://community.hubspot.com/t/adding-contact-to-list/103065 "2024-03-21T08:48:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prakashreddy](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Prakashreddy](https://community.hubspot.com/u/Prakashreddy)\
**Post date:** [March 21, 2024, 8:48am UTC](https://community.hubspot.com/t/adding-contact-to-list/103065/1 "2024-03-21T08:48:40Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![GRajput](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/grajput/32/102020_2.png) [@GRajput](https://community.hubspot.com/u/GRajput)\
**Post date:** [March 21, 2024, 10:57am UTC](https://community.hubspot.com/t/adding-contact-to-list/103065/2 "2024-03-21T10:57:33Z")

</div>

Hi @Prakashreddy

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

```lia-code-sample
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!

---

<div class="post-metadata">

**Author:** ![Prakashreddy](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Prakashreddy](https://community.hubspot.com/u/Prakashreddy)\
**Post date:** [March 22, 2024, 6:47am UTC](https://community.hubspot.com/t/adding-contact-to-list/103065/3 "2024-03-22T06:47:24Z")

</div>

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](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

```auto
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

---

<div class="post-metadata">

**Author:** ![Prakashreddy](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@Prakashreddy](https://community.hubspot.com/u/Prakashreddy)\
**Post date:** [March 22, 2024, 7:19am UTC](https://community.hubspot.com/t/adding-contact-to-list/103065/4 "2024-03-22T07:19:25Z")

</div>

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.
