BarcodeURL
Builds a URL that renders a barcode image from its inputs.
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 |
string | boolean | number | No | Show the encoded value as a text band beneath the barcode. Accepts true, false, 1, 0, "true", "false", "1", "0" |
altText |
string | No | Alternate text shown when showText is off |
rotation |
number | No | Orientation in degrees: 0, 90, 180 or 270 |
transparentBG |
string | boolean | number | No | Transparent instead of white background. Accepts true, false, 1, 0, "true", "false", "1", "0" |
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
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. showText and transparentBG also change the rendered image: all eight boolean-like literals are accepted, a truthy value draws the encoded value as a text band beneath the barcode (or makes the background fully transparent), and a falsy value omits the band (or leaves an opaque white background). All four truthy spellings produce the same image, as do all four falsy spellings. The qs token in the returned URL varies from call to call, but that is an encoding artefact — the underlying image is identical, and a token remains usable with no observed expiry.
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
ContentAreaBuildOptionList— other Content functions- Differs from official docs — the empty-value abort
- Official reference
- ampscript.guide