Runtime verified

Syntax

QueryParameter(parameterName)  →  string
1 argument — exactly

Parameters

Name Type Required Description
parameterName string Yes Query parameter name, matched without regard to case

Example

%%[
  VAR @source
  SET @source = QueryParameter("p")
]%%
Source: %%=v(@source)=%%

Requested with ?p=hello, this renders Source: hello.

Because a missing parameter is an empty string rather than a failure, a default is a two-line guard:

%%[
  VAR @source
  SET @source = QueryParameter("utm_source")
  IF Empty(@source) THEN
    SET @source = "direct"
  ENDIF
]%%

Return value

string — the decoded value of the named query-string parameter, or an empty string when the request carries no such parameter.

The value domain is open, so there is no closed set of tokens to test for. An absent parameter answers a real empty string: Empty() on the same call answers true at HTTP 200.

Behaviour

The name is matched without regard to case. With ?Foo=1 in the URL, QueryParameter("foo"), QueryParameter("FOO") and QueryParameter("Foo") each answered 1.

Percent-encoded characters arrive decoded. ?sp=a%20b gives a b, ?am=a%26b gives a&b, ?pc=100%25 gives 100%, and ?pl=a+b gives a b.

A parameter supplied twice is comma-joined. ?x=1&x=2 returns 1,2 as one string.

A platform-supplied name is readable. QueryParameter("PAGEURL") returned the full published page URL although the request never set it, and a caller-supplied ?PAGEURL=zzz then overrode it.

An empty name and a numeric name are accepted and always answer empty without aborting, so the parameter type stays string.

The value is returned unescaped, exactly as the caller supplied it. Escape it yourself before rendering it into markup — see RequestParameter.

There is no optional second argument

A second argument aborts the call with HTTP 422. All three spellings that other AMPscript flag parameters accept interchangeably were tried — the number 1, the number 0 and the boolean true — and each aborted its own branch while every other branch on the same deploy rendered normally. There is no hidden decode-or-not switch here; the same shape aborts on RequestParameter too.

Compared with RequestParameter and v

The official reference states that this function and RequestParameter behave the same way and are both retained for backward compatibility. On a GET CloudPage that holds byte-for-byte: both functions read the same parameter inside one block and returned identical strings of identical length for a plain value, a decoded space, a decoded ampersand, a percent sign, a missing parameter, a repeated parameter and a wrong-case name, with an in-page equality check answering the same. No GET input separated them. Pick either; prefer one consistently.

v is unrelated — it outputs a value it is given rather than reading the request.

Show test script
%%[
  VAR @b, @rp, @qp, @word, @num
  SET @b = RequestParameter("b")
  SET @word = "zeta"
  SET @num = 7

  /* known-good control: renders on every request, so a run of HTTP 422s
     can be told apart from a broken deploy */
  OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))
  OutputLine(Concat("GATE=[", @b, "]"))

  /* a parameter this request set itself, read by both functions and
     compared in-page */
  IF @b == "basic" THEN
    OutputLine(Concat("--- basic start ---"))
    SET @rp = RequestParameter("p")
    SET @qp = QueryParameter("p")
    OutputLine(Concat("RP=[", @rp, "] LEN=[", Length(@rp), "]"))
    OutputLine(Concat("QP=[", @qp, "] LEN=[", Length(@qp), "]"))
    OutputLine(Concat("EQ=[", IIf(@rp == @qp, "same", "diff"), "]"))
    OutputLine(Concat("--- basic done ---"))
  ENDIF

  /* percent-encoded and plus-encoded values arrive decoded; the length
     proves a real single character rather than the escape sequence */
  IF @b == "enc" THEN
    OutputLine(Concat("--- enc start ---"))
    OutputLine(Concat("SP=[", RequestParameter("sp"), "] LEN=[", Length(RequestParameter("sp")), "]"))
    OutputLine(Concat("AM=[", RequestParameter("am"), "] LEN=[", Length(RequestParameter("am")), "]"))
    OutputLine(Concat("PL=[", RequestParameter("pl"), "]"))
    OutputLine(Concat("PC=[", RequestParameter("pc"), "]"))
    OutputLine(Concat("SP_QP=[", QueryParameter("sp"), "]"))
    OutputLine(Concat("AM_QP=[", QueryParameter("am"), "]"))
    OutputLine(Concat("--- enc done ---"))
  ENDIF

  /* a parameter the request never carried: empty at HTTP 200 */
  IF @b == "absent" THEN
    OutputLine(Concat("--- absent start ---"))
    SET @rp = RequestParameter("nosuchparam")
    SET @qp = QueryParameter("nosuchparam")
    OutputLine(Concat("ABS_RP=[", @rp, "] LEN=[", Length(@rp), "]"))
    OutputLine(Concat("ABS_RP_CHK=[", IIf(Empty(@rp), "empty", "not-empty"), "]"))
    OutputLine(Concat("ABS_QP_CHK=[", IIf(Empty(@qp), "empty", "not-empty"), "]"))
    OutputLine(Concat("--- absent done ---"))
  ENDIF

  /* the name ignores case: fetch with a single mixed-case parameter */
  IF @b == "case" THEN
    OutputLine(Concat("--- case start ---"))
    OutputLine(Concat("LOW=[", RequestParameter("foo"), "] UPP=[", RequestParameter("FOO"), "] MIX=[", RequestParameter("Foo"), "]"))
    OutputLine(Concat("LOW_QP=[", QueryParameter("foo"), "] UPP_QP=[", QueryParameter("FOO"), "] MIX_QP=[", QueryParameter("Foo"), "]"))
    OutputLine(Concat("--- case done ---"))
  ENDIF

  /* the same name twice: joined by a comma, proven by the length */
  IF @b == "dup" THEN
    OutputLine(Concat("--- dup start ---"))
    OutputLine(Concat("DUP_RP=[", RequestParameter("x"), "] LEN=[", Length(RequestParameter("x")), "]"))
    OutputLine(Concat("DUP_QP=[", QueryParameter("x"), "]"))
    OutputLine(Concat("--- dup done ---"))
  ENDIF

  /* a name the platform supplies although the request never set it —
     and, with ?b=plat&PAGEURL=zzz, a caller value overriding it */
  IF @b == "plat" THEN
    OutputLine(Concat("--- plat start ---"))
    OutputLine(Concat("PAGEURL_RP=[", RequestParameter("PAGEURL"), "]"))
    OutputLine(Concat("PAGEURL_QP=[", QueryParameter("PAGEURL"), "]"))
    OutputLine(Concat("PAGENAME=[", RequestParameter("PAGENAME"), "]"))
    OutputLine(Concat("MID=[", RequestParameter("MID"), "]"))
    OutputLine(Concat("--- plat done ---"))
  ENDIF

  /* v() outputs a variable, a literal, a number and a nested call */
  IF @b == "vread" THEN
    OutputLine(Concat("--- vread start ---"))
    SET @rp = RequestParameter("p")
    OutputLine(Concat("V_VAR=[", v(@rp), "]"))
    OutputLine(Concat("V_LIT=[", v("p"), "]"))
    OutputLine(Concat("V_WORD=[", v(@word), "]"))
    OutputLine(Concat("V_NUM=[", v(@num), "]"))
    OutputLine(Concat("--- vread done ---"))
  ENDIF

  IF @b == "vnest" THEN
    OutputLine(Concat("--- vnest start ---"))
    OutputLine(Concat("V_NEST=[", v(RequestParameter("p")), "]"))
    OutputLine(Concat("--- vnest done ---"))
  ENDIF

  IF @b == "vnumlit" THEN
    OutputLine(Concat("--- vnumlit start ---"))
    OutputLine(Concat("V_NUMLIT=[", v(5), "]"))
    OutputLine(Concat("--- vnumlit done ---"))
  ENDIF

  /* an empty name and a numeric name: accepted, always empty */
  IF @b == "rpempty" THEN
    OutputLine(Concat("--- rpempty start ---"))
    OutputLine(Concat("RPEMPTY=[", RequestParameter(""), "] QPEMPTY=[", QueryParameter(""), "]"))
    OutputLine(Concat("--- rpempty done ---"))
  ENDIF

  IF @b == "rpnum" THEN
    OutputLine(Concat("--- rpnum start ---"))
    OutputLine(Concat("RPNUM=[", RequestParameter(1), "] QPNUM=[", QueryParameter(1), "]"))
    OutputLine(Concat("--- rpnum done ---"))
  ENDIF

  /* argument counts the signatures do not allow: each aborts its own
     branch with HTTP 422 while every branch above still renders */
  IF @b == "rp0" THEN
    OutputLine(Concat("RP0=[", RequestParameter(), "]"))
  ENDIF
  IF @b == "rp2" THEN
    OutputLine(Concat("RP2=[", RequestParameter("p", 1), "]"))
  ENDIF
  IF @b == "qp0" THEN
    OutputLine(Concat("QP0=[", QueryParameter(), "]"))
  ENDIF
  IF @b == "qp2num" THEN
    OutputLine(Concat("QP2NUM=[", QueryParameter("p", 1), "]"))
  ENDIF
  IF @b == "qp2zero" THEN
    OutputLine(Concat("QP2ZERO=[", QueryParameter("p", 0), "]"))
  ENDIF
  IF @b == "qp2bool" THEN
    OutputLine(Concat("QP2BOOL=[", QueryParameter("p", true), "]"))
  ENDIF
  IF @b == "v0" THEN
    OutputLine(Concat("V0=[", v(), "]"))
  ENDIF
  IF @b == "v2" THEN
    OutputLine(Concat("V2=[", v(@word, @word), "]"))
  ENDIF
]%%

The bundled harness is shared by all three functions and is driven entirely by query strings. A POST body is not exercised, so the form-field path the official reference mentions is untested here and the equivalence above is stated for GET only.

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next No

See also