BarcodeURL
Builds a URL that renders a barcode image from its inputs. Runtime-proven on a live Marketing Cloud Engagement CloudPage — including the real minimum argument count and the empty value that takes the whole page down.
Syntax
BarcodeURL(valueToConvert, barcodeType, width, height[, checksumValue, showText, altText, rotation, transparentBG]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
valueToConvert |
string | Yes | The data to encode in the barcode |
barcodeType |
string | Yes | The symbology, e.g. code128auto, code39, ean13 |
width |
number | Yes | Image width in pixels |
height |
number | Yes | Image height in pixels |
checksumValue |
string | No | Checksum value for the barcode |
showText |
boolean | No | Show the encoded value beneath the barcode |
altText |
string | No | Alternate text shown when showText is off |
rotation |
number | No | Orientation in degrees: 0, 90, 180 or 270 |
transparentBG |
boolean | No | Transparent instead of white background |
Example
<img src="%%=BarcodeURL('12345678901', 'code128auto', 150, 50)=%%">
The function returns a bare URL, so it is wrapped in an <img> tag by the caller. The four-argument form above renders <img src="http://cl.s7.exct.net/LiveContent.aspx?qs=…"> — a LiveContent URL that serves the barcode image.
All nine arguments together select formatting options and still return a single URL:
%%[
VAR @code
SET @code = BarcodeURL("12345678901", "code128auto", 150, 50, "", 1, "MyAlt", 90, 1)
]%%
<img src="%%=v(@code)=%%">
Return value
string — a LiveContent URL that renders the requested barcode image. The URL is opaque and varies per call, so there is no closed set of values to test for. The function returns the URL only, never a complete <img> element.
Behaviour
Four arguments are the minimum. Value, symbology, width and height alone return a URL at HTTP 200. A three-argument call aborts the page with HTTP 422. Our own catalog previously encoded a minimum of nine arguments even though arguments five through nine were already flagged optional; it has been corrected to four.
The optional arguments are accepted and change the URL. Supplying checksumValue, showText, altText, rotation and transparentBG each produces a distinct URL, up to the full nine-argument form.
An empty value aborts the page. Passing an empty string as valueToConvert aborts the CloudPage with HTTP 422 and discards everything rendered before it, rather than returning an empty string or a blank-barcode URL. Guard the value before calling — see Differs from official docs. Note also the documented per-page limit: BarcodeURL may be called at most twice per message or landing page.
Show test script
%%[
VAR @b, @four, @opts
SET @b = RequestParameter("b")
/* safe sweep: two accepted calls (the per-page limit) share one request */
IF @b == "safe" THEN
SET @four = BarcodeURL("12345678901", "code128auto", 150, 50)
OutputLine(Concat("four=[", @four, "]"))
SET @opts = BarcodeURL("12345678901", "code128auto", 150, 50, "", 1, "MyAlt", 90, 1)
OutputLine(Concat("opts=[", @opts, "]"))
ENDIF
/* an empty value aborts the page: the start marker never renders */
IF @b == "empty" THEN
OutputLine(Concat("empty start"))
OutputLine(Concat("empty=[", BarcodeURL("", "code128auto", 150, 50), "]"))
OutputLine(Concat("empty done"))
ENDIF
/* three arguments is below the minimum of four and aborts the page */
IF @b == "few" THEN
OutputLine(Concat("few start"))
OutputLine(Concat("few=[", BarcodeURL("12345678901", "code128auto", 150), "]"))
OutputLine(Concat("few done"))
ENDIF
]%%
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
ContentArea·BuildOptionList— other Content functions- Differs from official docs — the empty-value abort
- Official reference · ampscript.guide