---
title: "The Email Experience Manager Client API"
slug: "the-email-experience-manager-client-api"
abstract: "Use the Email Experience Manager Client API to manage subscriptions."
---
# The Email Experience Manager Client API

The Email Experience Manager *ClientAPIService* class, `Sitecore.EmailCampaign.Cd.Services.ClientAPIService`, is used by EXM to handle subscribes and unsubscribes. You can use it to manage subscriptions to lists in the List Manager and send automated email messages.

The Email Experience Manager Client API (ClientApiService ) is registered in the IOC container, so you can either inject it into the constructor of your class or you can use the ServiceLocator, for example:

```csharp
IClientApiService _clientApiService;public MyConstructor(IClientApiService clientApiService)
{
  _clientApiService = clientApiService;
}

```

or

```text
IClientApiService clientApiService = ServiceLocator.ServiceProvider.GetService< IClientApiService >()

```

The `ClientAPIService` API is only registered on the CD role. And the CD server is not configured to add or remove contacts from a List Manager list, or to send EXM campaigns. Therefore, if you’re working in a scaled server setup, you must use the *ClientAPIService* request to delegate that work to the CM servers.

The following diagram depicts this process:

![Client API request process.](<https://doc.sitecore.com/api/markdown-image/xp/en/developers/exm/91/email-experience-manager/images/EXM%20Client%20API%209.0+.png>)

The following public methods are available on the `IClientApiService`:

- [SendAutomatedMessage](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273110992993554)
- [UpdateListSubscription](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273110992972016)

These methods use a `ContactIdentifier` to identify the contact that you want to do the operation. For more information, see [Contact identifiers](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/contact-identifiers.html) and [Identifying contacts](https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/identifying-contacts.html).

The first public method is described in the following table.

- **Name:**: SendAutomatedMessage
- **Description:**: This method sends an activated automated email campaign (automatedMessage.MessageId) to the contact (automatedMessage.ContactIdentifier) with the option to specify a set of custom tokens and the target language, as well as a set of custom query string parameters that are used when rendering the email campaign during dispatch.You can extend the AutomatedMessage class using the CustomQueryStringParameters property so that additional query string parameters are supported (for example, IDictionary<string, string> CustomQueryStringParameters).The WebPageMail body link is generated in the GenerateBodyLink pipeline. This pipeline is executed during the email dispatch when EXM generates the link to download the email campaign contents. The pipeline generates the base URL, adds default query string parameters, and then adds custom query string parameters. For example:The code injected inside the .cshtml for this example looks like this:

```

http://XXXX/?sc_itemid=XXX&sc_lang=XXX&sc_pd_view=XXX&yourParam=someValue&
ec_eq=XXX

```
```csharp
@{
	string customQueryString = Request.Params["yourParam"];
	if (!string.IsNullOrWhiteSpace(customQueryString))
	{
		<div class="customquerystringparameters">@MvcHtmlString.Create(customQueryString)</div>
	}
}

```

- **Usage:**:

```text
void SendAutomatedMessage(AutomatedMessage automatedMessage)

```

The second public method is described in the table below.

| **Name:** | UpdateListSubscription |  |
| --- | --- | --- |
| Description: | This method allows you to update the list subscription for a contact. The operation property (`message.ListSubscribeOperation`) on the message determines which operation should be taken and can be set to any of the following values:<br><br><ul><li>[Subscribe](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273093069596970)</li><li>[Unsubscribe](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273093070222078)</li><li>[UnsubscribeFromAll](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273093070256014)</li><li>[AddToList](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_para-idm273093070267374)</li><li>[RemoveFromList](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-email-experience-manager-client-api.html#UUID-9a60d517-61dd-2dcc-1205-810335778213_N1546536934420)</li></ul><br><br>By default, EXM automatically registers an event when unsubscribing a contact. However, this can also be achieved using the `ClientApiService`, by defining the unsubscribe interaction data (`message.UnsubscribeInteractionData`). To do this, set the following parameters:<br><br><ul><li>message.MessageId: The email campaign id</li><li>message.InstanceId: The email campaign id</li><li>message.ManagerRootId: The id of the manager root associated with the email campaign</li><li>message.UnsubscribeInteractionData.MessageLanguage: The language the contact receives the email campaign in</li><li>message.UnsubscribeInteractionData.TestValueIndex: The variant number if the email campaign is an AB test</li><li>message.UnsubscribeInteractionData.EmailAddressHistoryEntryId: The id of the email address in the EmailAddressHistory facet.</li></ul> |  |
| **Operations:** | Subscribe | This operation adds the contact (`message.ContactIdentifier`) to the first non-segmented include list defined on the campaign (`message.MessageId`). If `message.RequireSubscriptionConfirmation` is set, EXM sends a confirmation email message to the contact, asking them to confirm the subscription before adding them to the list. In addition, the contact is removed from the default global opt-out list.<br><br>> [!note]<br>> You can [extend this functionality](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-exm-extensibility-points.html)by implementing the `SubscribeEvent` pipeline. |
|  | Unsubscribe | This operation removes the contact (`message.ContactIdentifier`) from all the contact lists that are included in the email campaign (`message.MessageId`). If the contact is successfully unsubscribed from a list and **Send unsubscribe confirmations** is enabled on the manager root, EXM sends the notification that is defined by the `StandardMessages.UnsubscribeNotification` setting to the contact If the contact could not be removed from any included contact lists or if the contact does not appear in any of the lists, the contact is instead added to the global opt-out list that is defined on the manager root. You can override this behavior in `UnsubscribeFromList`  pipeline.<br><br>> [!note]<br>> You can [extend this functionality](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-exm-extensibility-points.html) by modifying the `UnsubscribeFromList` pipeline. |
|  | UnsubscribeFromAll | This operation adds the contact (`message.ContactIdentifier`) to the global opt-out list that is defined on the manager root of the email campaign (`unsubscribeMessage.MessageId`).<br><br>> [!note]<br>> You can [extend this functionality](https://doc.sitecore.com/xp/en/developers/exm/91/email-experience-manager/the-exm-extensibility-points.html), if you implement the `UnsubscribeFromAllEvent` pipeline. |
|  | AddToList | This operation adds the contact (`message.ContactIdentifier`) to the contact list (`message.ListId`) |
|  | RemoveFromList | This operation removes the contact (`message.ContactIdentifier`) from the contact list (`message.ListId`) |