ExamplesHead over to our Github Repository to see examples of connected content scripts.
How does it work?
The very basic schema of the script looks as follows:Security
Without the following settings, each time a connected content message is triggered, it calls the Voucherify API at least two times. The following settings reduce the number of API calls invoiced by Braze and cut the risk of hitting the hard-blocking API limit that may break the message delivery.Rate limiter
First, limit the number of messages sent by Braze per minute. This secures both Braze and Voucherify APIs against hitting too much traffic from your campaign. When targeting users during campaign setup, choose to limit the sending rate to 500 messages per minute.Add caching to POST calls
All examples of Connected Content in this tutorial include default caching to reduce the number of API calls triggered by Braze. Note that removing cache from your script will double the number of Voucherify API calls used by Connected Content.
- Add a
:cache_max_ageattribute. By default, the caching duration is 5 minutes. You can customize the duration using seconds. It can be set between 5 minutes to 4 hours. Example::cache_max_age 3600will cache for 1 hour. - Provide a caching key
cache_id={{cache_id}}in the destination endpoint query parameter so Braze can identify a unique publication. First, define the variable and then append the unique query string to your endpoint. This will differentiate each publication by thesource_id.
Braze caches the API calls based on the URL. The unique string used as a query parameter is ignored by Voucherify, but it distinguishes different API requests for Braze and allows to cache each unique attempt separately. Without that query parameter, every customer will receive the same coupon code for the cache duration.
Retry attribute
Connected Content does not validate the Voucherify response, so we additionally recommend adding a retry attribute in the Connected Content script. The connected content logic will try to retry 5 times before aborting the message (it will respect the rate limiter). This method will help prevent cases of failed code publishing when it takes a little longer to fetch data from Voucherify. If you do not use:retry, then irrespective of the response returned from Voucherify, Braze will attempt to send the distribution, which may result in generating emails without a published code.
Unique publication per customer
Thesource_id parameter in the script body provides that each customer can receive only one unique code in a single Braze campaign. As a result, even if Braze unintentionally multiplies the request, each user will receive the same unique code that was published to him/her in the first message.
{{source_id}} and its effect on publications by using the following configurations:
Customer can join only once
If your Voucherify campaign has a limit Customers can join only once, remove publication source id from the script body. Voucherify will make sure that each Braze message to the same customer will deliver the same code that was published in the first place. Your Connected Content script should be as follows:Examples
Head over to our Github Repository to see examples of connected content scripts.
Publish and send unique coupon code
In this example, the Connected Content script calls Voucherify API to publish a unique coupon code and send it in the Braze message. Each Braze user receives only one unique code.Invite new referrers
This Connected Content script enables you to publish and send unique referral codes to selected Braze users. Each user receives only one referral code to share with other users and gain new referrals.Fetch loyalty card balance
Here is an example of a Connected Content script that pulls the current loyalty balance based on the loyalty card code that was sent beforehand to Braze as a custom attribute. Note that you need to store the loyalty card code as a custom attribute in Braze user’s profile before using this script.Display fetched data in Braze messages
We’re assuming you already have a Braze campaign or canva in which you want to use the connected content script.Step 1: Add connected content script to message template
- Copy and paste the Connected Content script under the
<body>tag in a message HTML template. Replace CAMPAIGN_ID with a Voucherifycampaign_idcopied from the URL address of Voucherify campaign dashboard.
- Paste your API endpoint. If you don’t know what your API endpoint is, you can check it in the Project settings > General > API endpoint.
- Add your API keys for authentication. You can find Voucherify-App-Id and ** in Project Settings > General > Application Keys.
Step 2: Create snippet to display fetched data
Responses from the Voucherify API is stored by connected content under the value of:save parameter. For example:
:save parameter in Connected Content script.

