We’ve migrated our documentation to a new site, which means some URLs have changed.
Subscriptions

How to allow users to subscribe to multiple ESP mailing lists from an offer template?

You are able to subscribe users to multiple ESP mailing lists with the help of the below JavaScript script:

  var email   = ::EMAIL::;      
  var API_URL = ::API_URL::;
  var SITE_ID = ::SITE_ID::;
  var MAILING_LISTS = [ ::MAILING_LISTS:: ];
  var body = {email: email, sqids: MAILING_LISTS};
  var xhr = new XMLHttpRequest();
  xhr.open('POST', API_URL + '/tracker/lucid/sub/' + SITE_ID, true);
  xhr.setRequestHeader('Content-type', 'application/json');
  xhr.send(JSON.stringify(body));

The values needed to be filled in are:

::EMAIL:: - the email of the user
::API_URL:: - the base URL of the API based on your ESP environment. For example, //api-esp.piano.io or //sandbox-api-esp.piano.io.
::SITE_ID:: - your Site ID in ESP
::MAILING_LISTS:: - an array of Mailing list IDs

Now in order for your users to be able to subscribe to the provided mailing lists, you can add the above script to your Offer template using the method <div custom-script> and use it to create and customize a template where subscribers can select and subscribe to multiple newsletters. This offer template can then be used in any Composer Experience.

As an alternative, you can create an out-of-the-box ESP Opt-in form and configure Groups of mailing lists for your audience. Then you can use the Show newsletter signup action card in Composer to show the form to your users. More information about this is available here.

Last updated: