Skip to main content
Use the following settings to optimize the performance of your Braze connected content scripts using Voucherify data. The 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.
The examples below use the default API address https://api.voucherify.io.If your API endpoint is in a different region, remember to change it.

Rate limiter

When configuring campaigns in Braze, 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. Limit the sending rate accordingly to your API rate limits in Voucherify. Consider your other API call needs.

Add caching to calls

Caching reduces the number of API calls triggered by Braze. Connected Content calls don’t cache by default and will make two API requests per each call. This can quickly drain your hourly and monthly limits. The caching mechanism limits that to one API call per one request. Add caching to calls as follows:
  • Provide a caching key cache_id={{cache_id}} in the destination endpoint query parameter, so Braze can identify a unique call. First, define the variable and then append the unique query string to your endpoint. In the example, this will differentiate each publication by the source_id.
  • Add a :cache_max_age attribute. You can customize the duration using seconds. It can be set between 5 minutes to 4 hours. Example: :cache_max_age 3600 will cache for 1 hour.
By default, the caching duration is 5 minutes.
Caching in publications
      {% assign braze_campaign_id = {{campaign.${api_id}}} %}
      {% assign customer_id = {{${user_id}}} %}
      {% assign source_id = braze_campaign_id | append: customer_id %}
      {% assign voucherify_campaign_id = "camp_XXXXXXXXXXXXXXXXXXXXXXXX" %}
      {% assign cache_id = source_id %}

      {% connected_content 
         https://api.voucherify.io/v1/publications?cache_id={{cache_id}}
         :method post
         :headers {
            "X-App-Id": "12345678-90QW-ERTY-UIOP-asdfghjklzxc",
            "X-App-Token": "MNBVCXZL-KJHG-FDSA-POIU-ytrewq098765"
         }
         :body campaign={{voucherify_campaign_id}}&customer={{customer_id}}&channel=Braze&source_id={{source_id}}
         :content_type application/json
         :cache_max_age
         :retry
         :save publication
      %}
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 value (for publications, the same coupon code) for the cache duration.

Retry attribute

Add a retry attribute in the Connected Content script, as Connected Content does not validate the Voucherify response. Braze will try to retry 5 times before aborting the message, while respecting the rate limiter. This method prevents cases like failed code publication when it takes a little longer to fetch data from Voucherify.
Publications without retryIf you use the POST v1/publications endpoint without :retry, Braze will attempt to send the distribution even if there’s no response returned from Voucherify.This may result in generating emails without a published code.
Retry in publications
      {% assign braze_campaign_id = {{campaign.${api_id}}} %}
      {% assign customer_id = {{${user_id}}} %}
      {% assign source_id = braze_campaign_id | append: customer_id %}
      {% assign voucherify_campaign_id = "camp_XXXXXXXXXXXXXXXXXXXXXXXX" %}
      {% assign cache_id = source_id %}

      {% connected_content 
         https://api.voucherify.io/v1/publications?cache_id={{cache_id}}
         :method post
         :headers {
            "X-App-Id": "12345678-90QW-ERTY-UIOP-asdfghjklzxc",
            "X-App-Token": "MNBVCXZL-KJHG-FDSA-POIU-ytrewq098765"
         }
         :body campaign={{voucherify_campaign_id}}&customer={{customer_id}}&channel=Braze&source_id={{source_id}}
         :content_type application/json
         :cache_max_age
         :retry
         :save publication
      %}

Unique publication per customer

The source_id parameter in the script body for publications ensures that each customer can receive only one unique code in a single Braze campaign. Even if Braze unintentionally multiplies the request, each user will receive the same unique code that was published to them in the first message.
Source ID in publications
      {% assign braze_campaign_id = {{campaign.${api_id}}} %}
      {% assign customer_id = {{${user_id}}} %}
      {% assign source_id = braze_campaign_id | append: customer_id %}
      {% assign voucherify_campaign_id = "camp_XXXXXXXXXXXXXXXXXXXXXXXX" %}
      {% assign cache_id = source_id %}

      {% connected_content 
         https://api.voucherify.io/v1/publications?cache_id={{cache_id}}
         :method post
         :headers {
            "X-App-Id": "12345678-90QW-ERTY-UIOP-asdfghjklzxc",
            "X-App-Token": "MNBVCXZL-KJHG-FDSA-POIU-ytrewq098765"
         }
         :body campaign={{voucherify_campaign_id}}&customer={{customer_id}}&channel=Braze&source_id={{source_id}}
         :content_type application/json
         :cache_max_age
         :retry
         :save publication
      %}
You can modify {{source_id}} and its effect on publications with the following configurations.
ConfigurationEffect
{{campaign.${dispatch_id}}}Ensures that all customers within a single send-out will use the same publication.
{{campaign.${api_id}}}Ensures that all customers within a single campaign will use the same publication.
{{${user_id}}} or {{${braze_id}}}Ensures that every customer will use the same publication no matter which campaign is sent (you can use ${user_id} which is an external ID and ${braze_id} which is an internal ID).
{{campaign.${dispatch_id}}} and {{campaign.${user_id}}}Each customer within a single send-out will use the same unique publication.

Publication with customer can join only once

If your Voucherify campaign is set to Customers can join campaign only once, remove publication source ID from the script body. Voucherify ensures that each Braze message to the same customer will deliver the same code that was published in the first message. Your Connected Content script should be as follows:
   {% assign braze_campaign_id = {{campaign.${api_id}}} %}
   {% assign customer_id = {{${user_id}}} %}
   {% assign cache_id = braze_campaign_id | append: customer_id %}
   {% assign voucherify_campaign_id = "camp_XXXXXXXXXXXXXXXXXXXXXXXX" %}

   {% connected_content 
      https://api.voucherify.io/v1/publications?cache_id={{cache_id}}
      :method post
      :headers {
            "X-App-Id": "12345678-90QW-ERTY-UIOP-asdfghjklzxc",
            "X-App-Token": "MNBVCXZL-KJHG-FDSA-POIU-ytrewq098765"
      }
      :body campaign={{voucherify_campaign_id}}&customer={{customer_id}}&channel=Braze
      :content_type application/json
      :cache_max_age
      :retry
      :save publication
   %}

Converting Connected Content scripts to Canvas

The examples above are prepared for Braze campaigns. However, you can use them in Braze Canvas as well. To use the script in Canvas, delete the line with {% assign braze_campaign_id = {{campaign.${api_id}}} %} and add {% assign braze_id = canvas.${id} %}.

Solving issues

If your Connnected Content script doesn’t show data from Voucherify API, go to Audit logs in Voucherify. Check if there are any errors and the request and response payloads.

Next steps

Last modified on March 20, 2026