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:
IClientApiService _clientApiService;public MyConstructor(IClientApiService clientApiService)
{
_clientApiService = clientApiService;
}
or
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:
The following public methods are available on the IClientApiService
:
These methods use a ContactIdentifier
to identify the contact that you want to do the operation. For more information, see Contact identifiers and Identifying contacts.
The first public method is described in the following table.
Name: |
SendAutomatedMessage |
Description: |
This method sends an activated automated email campaign ( You can extend the The RequestResponse
The code injected inside the .cshtml for this example looks like this: RequestResponse
|
Usage: |
RequestResponse
|
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 ( By default, EXM automatically registers an event when unsubscribing a contact. However, this can also be achieved using the
| |
Operations: |
Subscribe |
This operation adds the contact ( Note You can extend this functionality by implementing the |
Unsubscribe |
This operation removes the contact ( Note You can extend this functionality by modifying the | |
UnsubscribeFromAll |
This operation adds the contact ( Note You can extend this functionality, if you implement the | |
AddToList |
This operation adds the contact ( | |
RemoveFromList |
This operation removes the contact ( |