Runtime verified Test scripts included

Syntax

Base64Encode(value[, encoding])  →  string
1–2 arguments

Parameters

Name Type Required Description
value string Yes The value to encode; the empty string encodes to the empty string
encoding string No Name of the character encoding applied before encoding; defaults to UTF-8. Next accepts UTF-8, UTF-16, UTF-32 and ASCII; other names are rejected at save

Example

%%=Base64Encode("SFMC AMPscript 2026")=%%

Renders U0ZNQyBBTVBzY3JpcHQgMjAyNg==.

Return value

string — the Base64 form of the input, padded with = to a multiple of four characters.

There is no error token to test for: every accepted call returns an encoded string.

Behaviour

The output is standard Base64. Base64Encode("Hello") gives SGVsbG8=, and Length(Base64Encode("SFMC AMPscript 2026")) gives 28.

Padding comes out right for every length. Man gives TWFu with no padding, Ma gives TWE=, and M gives TQ==.

UTF-8 bytes are encoded by default. Base64Encode("café€") gives Y2Fmw6nigqw=, and naming "UTF-8" gives the same.

Four encoding names work. For the same café€ input:

Call Renders
Base64Encode("café€", "UTF-16") YwBhAGYA6QCsIA==
Base64Encode("café€", "UTF-32") YwAAAGEAAABmAAAA6QAAAKwgAAA=
Base64Encode("café€", "ASCII") Y2FmPz8=

UTF-16 and UTF-32 are little-endian. ASCII replaces é and € with question marks before encoding, without any warning.

Other encoding names are refused at save. An email containing UTF-16BE, ISO-8859-1, banana or an empty string as the encoding cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.

The empty string encodes to the empty string.

Wrong argument counts are refused at save. Base64Encode() and a call with three arguments are rejected the same way.

Show Next test script
<!-- Marketing Cloud Next test script for Base64Encode. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[SGVsbG8=] got=[%%=Base64Encode("Hello")=%%]</p>
<p>c2 expect=[U0ZNQyBBTVBzY3JpcHQgMjAyNg==] got=[%%=Base64Encode("SFMC AMPscript 2026")=%%]</p>
<p>c3 expect=[TWE=] got=[%%=Base64Encode("Ma")=%%]</p>
<p>c4 expect=[TQ==] got=[%%=Base64Encode("M")=%%]</p>
<p>c5 expect=[28] got=[%%=Length(Base64Encode("SFMC AMPscript 2026"))=%%]</p>
<p>c6 expect=[TWFu] got=[%%=Base64Encode("Man")=%%]</p>
<p>c7 expect=[Y2Fmw6nigqw=] got=[%%=Base64Encode("café€")=%%]</p>
<p>c8 expect=[Y2Fmw6nigqw=] got=[%%=Base64Encode("café€","UTF-8")=%%]</p>
<p>c9 expect=[YwBhAGYA6QCsIA==] got=[%%=Base64Encode("café€","UTF-16")=%%]</p>
<p>c10 expect=[YwAAAGEAAABmAAAA6QAAAKwgAAA=] got=[%%=Base64Encode("café€","UTF-32")=%%]</p>
<p>c11 expect=[Y2FmPz8=] got=[%%=Base64Encode("café€","ASCII")=%%]</p>
<p>c12 expect=[] got=[%%=Base64Encode("")=%%]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode("café€","UTF-16BE")=%%

<!-- email 2: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode("café€","ISO-8859-1")=%%

<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode("Man","banana")=%%

<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode("Man","")=%%

<!-- email 5: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode()=%%

<!-- email 6: expect that the save is rejected (HTTP 400) -->
%%=Base64Encode("Man","UTF-8","extra")=%%

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 68.0

See also