Overview
You can use this request to subscribe or unsubscribe a contact from a specific list. If a particular subscription already exists, the subscription will be updated.
- To subscribe a contact, set the status to subscribed.
- To unsubscribe a contact, set the status to unsubscribed.
- To remove a contact’s subscription, set both the email and mobile status to an empty string.
The Method
| API | - | Method |
|---|---|---|
| REST | POST | https://[Your URL]/api/2.0/list_subscriptions/:list_id |
| XML-RPC | Call | list._subscriptions.ListSubscription |
Your URL is the address of your install.
Your method must be structured as follows:
ListSubscription(int $list_id, \struct | array $properties) : boolean
Parameters
| Property | Type | Description | Default | Required | Read Only |
|---|---|---|---|---|---|
| list_id | integer | List identifier | empty | yes | no |
| contact_id | integer | Contact identifier | empty | yes | no |
| email_status | string | Mapping email status Possible values: subscribed unsubscribed confirmed unconfirmed forwarded | empty | no | no |
| mobile_status | string | Mapping mobile status Possible values: subscribed unsubscribed confirmed unconfirmed forwarded | empty | no | no |
Even though they aren’t marked as required, you must include either the mobile_status or email_status properties.
Responses
| Type | Description |
|---|---|
| boolean | Whether or not the subscription was created. |
Code Samples
PHP (using REST API):
$json = '
{
"list_id":4,
"contact_id":1,
"email_status":"unsubscribed"
}
';
$url = '(Your URL)/api/2.0/list_subscriptions/:list_id';
$method = 'POST';
$cSession = curl_init();
$headers = array();
$auth = base64_encode($username . ':' . $apikey);
$headers[] = 'Authorization: Basic ' . $auth;
curl_setopt($cSession, CURLOPT_URL, $url);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, false);
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, strtoupper($method));
curl_setopt($cSession, CURLOPT_POSTFIELDS, $json);
$headers[] = 'Content-Type: application/json';
curl_setopt($cSession, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($cSession);
curl_close($cSession);