Salesforce Marketing Cloud

Follow this tutorial to get unique promo codes from Voucherify and send them to your customers via Salesforce Marketing Cloud.  

Contents

Before you start

When scheduling distributions with Voucherify via Salesforce Marketing Cloud, keep your API calls limits in mind. Salesforce supports Send Throttle to control the number of messages delivered to your customers in a particular time frame. Please note that exceeding your API calls limit blocks your access to Voucherify API and may break the distribution.

We highly recommend setting up the limit to 500 per minute to ensure a seamless workflow between Voucherify and Salesforce Marketing Cloud.


AMPscript Configuration

The integration between Salesforce Marketing Cloud and Voucherify allows you to request unique codes from Voucherify campaigns and pass them to your customers via Salesforce Marketing Cloud send-outs. This integration requires you to call Voucherify API using the Salesforce AMPscript. 

Using Salesforce AMPscripts and Dynamic Content, we're going to add Voucherify unique codes to Salesforce Marketing Cloud’s send-outs. You can use Voucherify campaigns with unique discount coupons, gift cards, loyalty cards, and referral codes. 

Go to your Salesforce Marketing Cloud account and prepare a new send-out script.

To get a unique code for a specific customer, you need to do the following:

  • Add the HTTPPost function to communicate with Voucherify. This function will use one of the Voucherify methods to get a unique code.
  • Call Voucherify Create Publication API to retrieve a unique code.

When calling the Create Publication method in Voucherify API, you need to define which customer should be assigned to a particular coupon code. 

Here is a code snippet with an example AMPscript configuration.


Step 1: Add your API endpoint and API keys 

If you don't know what your API endpoint is, you can check it in the Project settings > General > API endpoint.

API Endpoint

The table below shows an example list of clusters and associated endpoints.

Shared Cluster

Endpoint for Salesforce Marketing Cloud
Europe (default) https://api.voucherify.io/v1/publications
United States https://us1.api.voucherify.io/v1/publications
Asia (Singapore) https://as1.api.voucherify.io/v1/publications

Copy your API keys from the Project Settings > Application Keys.

Application Keys


Step 2: Add Voucherify Campaign

Replace the campaign_id_value variable with your Voucherify campaign identifier.

You can find the campaign id in the URL while displaying campaign details in the dashboard. This campaign will be the source of codes for your send-out. 

Campaign ID


Step 3: Map your Customer to Voucherify

If your campaign relies on sending unique codes to each customer, then it is important to map your customers in the Salesforce Marketing Cloud database to a unique identifier stored in Voucherify.

On the other hand, if your campaign does not require such granularity, then you can skip this configuration. Additionally, you may skip this step if your Voucherify campaign has a limit " Customers can join only once" because Voucherify will make sure that each Salesforce message to the same customer (i.e., email, SMS, etc) will deliver the same code that was published initially.

In this step, we will map the @salesforce_customer_id and define the publication @source_id. The @salesforce_customer_id refers to a unique identifier of a customer. You can define a customer using the Salesforce _subscriberkey attribute, which is the user-defined unique identifier representing a Subscriber. You can alternatively use your CRM attributes; it can be an email, a phone number, or another characteristic of your choice.

Once the HTTP POST request is sent, Voucherify will create a customer with your custom id mapped to the customer @source_id. The customer @source_id is a unique customer identifier in Voucherify.

The @source_id in the AMPScript refers to an optional parameter that identifies a unique publication call in Voucherify. If you wish to send out vouchers using multiple channels (emails, SMS, etc) and have the same result (send the same code), make sure that the publication source_id in the different send-outs is the same for each customer. Read more about Publication source_id in this guide.

Your AMPscript should be as follows:

    /* Get customer data from SalesForce Marketing Cloud  */
    SET @salesforce_customer_id = _subscriberkey
    SET @job_id = jobid 
    SET @source_id = Concat(@salesforce_customer_id, @job_id)

Step 4: Prepare the payload

The payload defines the customer who is to receive the code and the campaign from which the code will issued.

    /* Prepare the payload */
    SET @payload = Concat('{ 
        "campaign":",' @campaign_id, '", 
        "customer":",' @salesforce_customer_id, '", 
        "channel":"Salesforce Marketing Cloud", 
        "source_id":"' @source_id'"}')

Step 5: Send the request

Salesforce will use the prepared data to send a request to Voucherify. Voucherify will verify if a voucher can be issued and will return it to the AMPscript.


Step 6: Verify the response (optional)

Verify if the request was successful. If you do not receive a voucher, you can prevent the send-out.

Voucherify may not return a successful response if you have a static campaign. For a static campaign, Voucherify does not generate new codes once all of the codes in the current batch are assigned to customers. You can change your campaign settings using the Auto-update feature in the Campaign Manager to ensure that the number of codes initially created does not run out. This way Voucherify will add a new batch of codes once you have and you assigned all of the coupons in the campaign to other customers.

Finally, you need to add the following code snippet to the body in order to display the published voucher code.


Code Example

We just went through the above example workflow to show you how to configure the AMPscript to get unique promo codes from Voucherify. Below you will find an example code block. 


%%[
    /* Set connection data */
    SET @appID = "VOUCHERIFY-APP-ID"
    SET @appSecretKey = "VOUCHERIFY-SECRET-KEY"
    SET @targetURL = https://api.voucherify.io/v1/publications

    /* Set Voucherify's campaign ID - the source of vouchers */
    SET @campaign_id = "campaign_id_value"
    
    /* Get customer data from SalesForce Marketing Cloud  */
    SET @salesforce_customer_id = _subscriberkey

    /* Get the details about the job sendout to use as the source_id */
    /* jobid - Returns the unique job identifier related to the email send */
    SET @job_id = jobid 
    SET @source_id = Concat(@salesforce_customer_id, @job_id)

    /* Prepare the payload */
    SET @payload = Concat('{ 
        "campaign":",' @campaign_id, '", 
        "customer":",' @salesforce_customer_id, '", 
        "channel":"Salesforce Marketing Cloud", 
        "source_id":"' @source_id'"}')

    /* Send the request */
    VAR @request, @response
    SET @request = HTTPPOST(
        @targetURL,
        "application/json",
        @payload,
        @response,
        "X-App-Id",
        @appID,
        "X-App-Token",
        @appSecretKey
    )

    /* If request failed, do not send out the message */
    IF @request != '200' THEN
        RaiseError('Request failed', true)
    ENDIF
]%%

<script runat="server">
  Platform.Load('Core','1');
  var resp = Variable.GetValue("@response");
  var json = Platform.Function.ParseJSON(resp);
  Variable.SetValue("@code",json.voucher.code)
</script>
 
Here is your voucher code: %%=v(@code)=%%
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us