How to Generate Barcodes and QR Codes in Salesforce Marketing Cloud Engagement
Generating barcodes and QR codes in Salesforce Marketing Cloud Engagement (SFMCE) is one of those “small” capabilities that quickly becomes mission-critical when you run direct mail, event check-in, couponing, warranties, or in-store redemption. The challenge is that SFMC renders email at send time, images are cached and proxied by inbox providers, and not every approach scales the same. The practical goal is simple: produce a code that is unique per subscriber, deterministic, and safe to render inside email and landing pages without breaking deliverability or performance.
When to use barcodes vs QR codes in SFMC
Barcodes (like Code128) are still common for operational scanning flows, especially where existing scanners and POS systems are optimized for 1D formats. SFMC supports this natively via AMPscript, which is ideal when you want a simple “value in, image out” pattern without maintaining your own rendering service. The AMPscript function is designed to generate an image URL for a barcode based on parameters you pass, which is exactly what SFMC documents for its built-in barcode URL generation function (AMPscript barcode image URL generation).
QR codes are typically better when the payload needs to be longer (URLs, JSON-like tokens, deep links) and when the scan device is a phone camera. In SFMC, QR code generation is usually done through an external service or custom script patterns rather than a single official native QR helper, which affects how you design for scale and resiliency.
Native AMPscript barcode URLs (fastest, least moving parts)
If you need a 1D barcode, this is the cleanest approach in SFMC because the platform gives you a deterministic function that outputs an image URL you can place directly into an email or CloudPage.
In practice, you generate the encoded value from subscriber attributes (or Data Extension fields) and output an `` tag that points to the generated barcode image.
%%[
/*Example: build a redemption code from subscriber attributes */
var @memberId, @offerId, @payload, @barcodeUrl
set @memberId = AttributeValue("MemberId")
set @offerId = AttributeValue("OfferId")
/* Keep it simple and scanner-friendly */
set @payload = Concat(@memberId, "-", @offerId)
/* Generate a barcode image URL */
set @barcodeUrl = BarcodeURL(@payload, "Code128", 2, 80)
]%%
<img src="%%=v(@barcodeUrl)=%%" alt="Barcode" width="320" height="80" style="display:block;border:0;" />
A common issue is null or missing attributes at send time. Using `AttributeValue()` reduces hard failures because it’s designed to safely fetch a value even when a field is absent, which is a practical detail called out in guidance on avoiding empty personalization values with AttributeValue. That matters here because a blank payload can produce an unusable code (or worse, identical codes across recipients).
QR code via third-party generator (flexible, but design for scale)
If you’re generating QR codes that encode URLs (for example, `https://example.com/redeem?token=…`), the typical pattern is to build the URL in AMPscript, then pass it to a QR rendering endpoint and output an image tag.
The catch is scale. In real sends, image generation can become a bottleneck if you’re creating a unique QR for every recipient and the QR service isn’t designed for high concurrency. Teams discussing scalable options point out that you need to think about caching, throughput, and what happens when an external endpoint slows down during a large blast, not just whether it works in a preview (scalability concerns when relying on third-party QR endpoints).
A practical mitigation is to make the QR image URL deterministic (same input yields same URL) so it can be cached by the provider and by intermediate layers more effectively. Another is to pre-generate and store QR image URLs in a Data Extension if the token doesn’t need to be computed at open time.
QR code via Server-side JavaScript (SSJS) libraries on cloud page
Salesforce Marketing Cloud does not natively support QR code generation, so you need to rely on external APIs or custom logic. The SSJS library approach solves this cleanly by generating the QR code on a CloudPage and then reusing it inside emails. You can either build the library yourself or use an existing implementation, for example the qrcode-sfmc-ssjs project available on GitHub.
For my exapmles I have found SFMC SSJS QR create library that does the trick here is what I’ve learnt and how I’ve implemented the QR code inside email.
CloudPage that generates the QR code
Before we create a cloud page we create a snippet code where we place entire above mentioned SSJS library, do not forget to wrap the library with <script runat="server"> tags.
After this is done we can create a CloudPage that acts as a QR generator endpoint.
This page:
- Accepts input via URL parameters (for example
data,id,url) - Uses SSJS + the library to generate the QR image
- Outputs the QR code as an
<img>response
%%=ContentBlockById("SSJS_QR_LIBRARY")=%%
<script runat="server">
HTTPHeader.SetValue("Content-Type", "text/plain;");// to reduce returned code
var data = Request.GetQueryStringParameter("data");
if (!data) throw 'No data';
var qrt = new QRCode({
"content": data,
"width": 300,
"height": 300,
"color": "black",
"background": "white",
"pretty" : false //to reduce returned code
}).table();
Variable.SetValue("@QRCodeTable", qrt);
</script>
%%=v(@QRCodeTable)=%%
Email template that displays the QR code
Now that we have created the QR code generating service we need to display our code in the email.
%%[
var @pageUrl, @data, @requestUrl, @qrcode
set @pageUrl = "YOUR_LANDING_PAGE_LINK_HERE"
set @data = "YOUR_TEXT_TO_ENCODE_HERE"
set @requestUrl = Concat(@pageUrl, "?data=", UrlEncode(@data, 1, 1))
set @qrcode = TreatAsContent(HTTPGet(@requestUrl))
]%%
%%=v(@qrcode)=%%
Advanced settings with QR generating cloud page
To create a fully configurable QR code service on your Clo
đź”’ This content is for Premium Subsribers only.
Please log in to preview content. Log in or Register
You must log in and have a Premium Subscriber account to preview the content.
When upgrading, please use the same email address as your WordPress account so we can correctly link your Premium membership.
Please allow us a little time to process and upgrade your account after the purchase. If you need faster access or encounter any issues, feel free to contact us at info@martechnotes.com or through any other available channel.
To join the Discord community, please also provide your Discord username after subscribing, or reach out to us directly for access.
You can subscribe even before creating a WordPress account — your subscription will be linked to the email address used during checkout.
Premium Subscriber
19,99 € / Year
- Free e-book with all revisions - 101 Adobe Campaign Classic (SFMC 101 in progress)
- All Premium Subscriber Benefits - Exclusive blog content, weekly insights, and Discord community access
- Lock in Your Price for a Full Year - Avoid future price increases
- Limited Seats at This Price - Lock in early before it goes up








