({{, (RefLink[URLQueryEncode, paclet:ref/URLQueryEncode])[\[LeftAssociation](Subscript[key, 1])->(Subscript[val, 1]),(Subscript[key, 2])->(Subscript[val, 2]),…\[RightAssociation]] 
creates a URL-style query string from an association of keys and values. }, {, (RefLink[URLQueryEncode, paclet:ref/URLQueryEncode])[{(Subscript[param, 1])->(Subscript[val, 1]),(Subscript[param, 2])->(Subscript[val, 1]),…}] 
creates a query string from a list of rules.}})

OpenersNotesSection(Spacer1)Details and Options

The (Subscript[val, i]) can be strings, numbers, or the following special forms:

(RefLink[URLQueryEncode, paclet:ref/URLQueryEncode]) has the option (RefLink[CharacterEncoding, paclet:ref/CharacterEncoding]), which specifies what type of character encoding to use for the output. The default is "UTF-8".

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Encode a list of parameters:

URLQueryEncode[{"name"->"John Doe","title"->"Reg. Manager: Northwest"}]

Use (RefLink[Missing, paclet:ref/Missing]) or (RefLink[None, paclet:ref/None]) to represent a missing parameter value:

URLQueryEncode[<|"user" -> Missing, "number"->3, "other" -> None|>]

Nested lists are flattened:

URLQueryEncode[<|"number" -> {1, 2, 3}, "name" -> {"jack", "john", "bob"}|>]

(RefLink[URL, paclet:ref/URL]) and (RefLink[CloudObject, paclet:ref/CloudObject]) can be encoded as values:

URLQueryEncode[{"url" -> CloudObject[]}]

URLQueryEncode[{"url"->URL["http://www.wolfram.com"]}]

OpenersExampleSection1(Spacer1)Options  (3)

OpenersExampleSubsection0(Spacer1)CharacterEncoding  (1)

Percent encode with a specified encoding:

URLQueryEncode[{"university"->"Eötvös Loránd University"}, CharacterEncoding->"MacintoshRoman"]

OpenersExampleSubsection1(Spacer1)SortQueries  (1)

Sort query parameters by using "SortQueries":

URLQueryEncode[{"c"->4,"z"->1,"a"->2}, "SortQueries" -> True]

URLQueryEncode[{"c"->4,"z"->1,"a"->2}]

OpenersExampleSubsection2(Spacer1)RemoveEmptyQueries  (1)

Remove empty parameters by using "RemoveEmptyQueries":

URLQueryEncode[{"a"->2,"c"->4,"z"->None}, "RemoveEmptyQueries" -> True]

URLQueryEncode[{"a"->2,"c"->4,"z"->None}]

OpenersExampleSection2(Spacer1)Possible Issues  (1)

Repeated keys are not supported by (RefLink[Association, paclet:ref/Association]):

URLQueryEncode[<|"value"->1,"value"->2|>]

To specify multiple values, collect them in a list:

URLQueryEncode[<|"value"->{1, 2}|>]

Alternatively, use a list of rules:

URLQueryEncode[{"value"->1,"value"->2}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[URLQueryDecode, paclet:ref/URLQueryDecode])  ▪  (RefLink[URLBuild, paclet:ref/URLBuild])  ▪  (RefLink[URLEncode, paclet:ref/URLEncode])  ▪  (RefLink[URLDecode, paclet:ref/URLDecode])  ▪  (RefLink[URLParse, paclet:ref/URLParse])  ▪  (RefLink[URLExecute, paclet:ref/URLExecute])  ▪  (RefLink[URLRead, paclet:ref/URLRead])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[URL Manipulation, paclet:guide/URLManipulation])}, {▪(RefLinkPlain[Web Operations, paclet:guide/WebOperations])}})}})