---
schema_version: "1"
id: 9c3e79549132b14883211e8d5c5ce32083ea6582bc6d02bab5c3071d58035267
title: UrlEncode
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/guides/mc-programmatic-content/ssjs_platformHTTPUrlEncode.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformHTTPUrlEncode.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 30f057cf39c29b1de604f7aad815f53fbd12ef2f58cb9dec1b5c9619cc78ecf7
products:
  - Marketing Cloud Engagement APIs and Programmatic Languages
  - Marketing Cloud
---
# UrlEncode

Performs percent-encoding on a URL.

These characters have reserved uses in URLs: `! # $ & ' ( ) * + , / : ; = ? @ [ ]`. Reserved characters serve a specific purpose in the context of a URL, so they must be encoded when they’re included in a URL for another purpose. For example, the question mark (`?`) character is used to separate the base URL from a query string. If the text that’s specified within the query string includes a question mark character, that character must be encoded.

**note:** This function performs character _encoding_. It doesn’t _encrypt_ the query parameters in the URL. To encrypt values in a query string for use in CloudPages, use the AMPscript [CloudPagesURL()](/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-sites/mc-ampscript-reference-sites-cloud-pages-url.html) function.

## Syntax

`UrlEncode(1, 2)`

## Properties

| Ordinal | Type    | Description                                                                                                                                                                                                                                                                                                                                                      |
| ------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `1`     | String  | Required. The URL to encode. The specified value must be a complete URL in order to be percent-encoded.                                                                                                                                                                                                                                                          |
| `2`     | Boolean | Specifies the extent of the encoding. If the value is `true`, all reserved characters in the URL are converted to percent-encoded values, except for space characters, which are encoded with the plus sign (`+`). If the value is `false`, space characters are converted to `%20`, but no other reserved characters are encoded. The default value is `false`. |

## Example

This example shows how URLs are percent-encoded when the value of the second operand is `true` or `false`.

```
<script runat="server">
  var baseURL = "http://www.example.com?value=12+3 12;3";
  var urlEncodeDefault = Platform.Function.UrlEncode(baseURL);
  var urlEncodeOperand2True = Platform.Function.UrlEncode(baseURL, true);
</script>

<table>
  <tr>
    <th>Description</th>
    <th>Value</th>
  </tr>
  <tr>
    <td>Base URL</td>
    <td><ctrl:var name="baseURL" /></td>
  </tr>
  <tr>
    <td>Value when operand 2 equals false (default)</td>
    <td><ctrl:var name="urlEncodeDefault" /></td>
  </tr>
  <tr>
    <td>Value when operand 2 equals true</td>
    <td><ctrl:var name="urlEncodeOperand2True" /></td>
  </tr>
</table>
```

The example outputs these values.

| Description                                 | Value                                        |
| ------------------------------------------- | -------------------------------------------- |
| Base URL                                    | http://www.example.com?value=12+3 12;3       |
| Value when operand 2 equals false (default) | http://www.example.com?value=12+3%2012;3     |
| Value when operand 2 equals true            | http://www.example.com?value%3d12%2b3+12%3b3 |
