> For the complete documentation index, see [llms.txt](https://docs.toomuchmedia.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode.md).

# nats\_encode

*Article Topics:* [*Smarty*](/getting-started/common-topics/smarty.md)*,* [*Customization*](/getting-started/common-topics/customization.md)

## **Parameters**

(*Required parameters in **bold**)*

| Parameter                                                                                                       | Description                                                                  | Possible Values                            | Default Value                                          | Example                |
| --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------ | ------------------------------------------------------ | ---------------------- |
| programid                                                                                                       | The [program](/additional-resources/common-terms.md#program) number          | Any valid program number.                  | The default program ID number                          | programid="123"        |
| campaign                                                                                                        | The [campaign ](/additional-resources/common-terms.md#campaign)number        | Any valid campaign number.                 | The default campaign ID number                         | campaign="123"         |
| siteid                                                                                                          | The [site](/additional-resources/common-terms.md#site) number                | Any valid site number.                     | The default site ID number                             | siteid="123"           |
| tourid                                                                                                          | The [tour](/additional-resources/common-terms.md#tour) number                | Any valid site number                      | No tour number                                         | tourid="123"           |
| adtoolid                                                                                                        | The [ad tool's](/additional-resources/common-terms.md#ad-tool) number        | Any valid adtool number                    | No adtool number                                       | adtoolid="123"         |
| subid1                                                                                                          | First optional tracking number.                                              | Any valid tracking number.                 | Doesn't use a tracking number                          | subid1="123"           |
| subid2                                                                                                          | Second optional tracking number.                                             | Any valid tracking number                  | Doesn't use a tracking number                          | subid2="123"           |
| userid                                                                                                          | The affiliate's I.D. number (loginid)                                        | Any valid affiliate I.D. number            | No affiliate                                           | userid="123"           |
| url                                                                                                             | If set, output contains an fully-qualified URL instead of just the linkcode. | 0 or 1 (exclusive).                        | Not set; doesn't create a banner link.                 | url="1"                |
| banner                                                                                                          | If set, creates a banner link.                                               | 0 or 1 (exclusive)                         | Not set; doesn't create banner link.                   | banner="1"'            |
| unencoded                                                                                                       | If set, overrides the affiliate default encoding                             | 0 (encoded) or 1 (unencoded) - (exclusive) | Not set; outputs affiliate default version of linkcode | unencoded="1"          |
| [assign](/nats-admin/skins-and-templates/further-reading/template-function-parameters/assign.md)                | Store output in this variable                                                | Any valid Smarty variable name             | *See output section below*                             | assign="my\_var"       |
| [assign\_prefix](/nats-admin/skins-and-templates/further-reading/template-function-parameters/assign_prefix.md) | Prefix output variables with this word. (Click link for details)             | Any valid Smarty variable name             | *None.* (No prefix is used)                            | assign\_prefix="myvar" |

## Note

To create an array of linkcodes, please see the [nats\_list\_linkcodes](/nats-admin/skins-and-templates/further-reading/template-functions/nats_list_linkcodes.md) page.

## Example

```
URL?nats={nats_encode userid=$toid program=# site=# tourid=# }{$encoded}
```

Outputs a linkcode. For example: [www.examplesite.com?nats=MS4yLjMuNS4wLjAuMC4wLjA](http://www.examplesite.com?nats=MS4yLjMuNS4wLjAuMC4wLjA). *userid =$toid* encodes the link specifically for the affiliate that the email is sent to. The linkcode is also placed in the variable, {$encoded}.

## Related Articles&#x20;

{% content-ref url="/pages/i3O7hbBtakLor7fKkgeA" %}
[nats\_decode](/nats-admin/skins-and-templates/further-reading/template-functions/nats_decode.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toomuchmedia.com/nats-admin/skins-and-templates/further-reading/template-functions/nats_encode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
