# encodeBase64ToBase64Url

## `encodeBase64ToBase64Url` Function

The `encodeBase64ToBase64Url` function transforms a standard **Base64-encoded string** into a **Base64URL-safe format**, which is commonly used in web tokens, URLs, and other contexts where Base64 characters (`+`, `/`, `=`) may be problematic.

***

### Purpose

Use this function when you need to:

* Convert a **Base64-encoded value** into a **Base64URL-safe variant**
* Ensure compatibility with URL-safe systems such as JWT (JSON Web Tokens)
* Pass encoded values in query strings or API endpoints

> 🔗 Specification: [Base64URL Standard – base64.guru](https://base64.guru/standards/base64url)

***

### Function Definition

| Property          | Description                         |
| ----------------- | ----------------------------------- |
| **Function Name** | `this.encodeBase64ToBase64Url`      |
| **Type**          | `function`                          |
| **Available In**  | Server-Side Variables               |
| **Returns**       | `string` (Base64URL-encoded string) |

***

### Parameters

| Parameter | Description                   | Type     | Required                                      | Example      |
| --------- | ----------------------------- | -------- | --------------------------------------------- | ------------ |
| `input`   | A valid Base64-encoded string | `string` | <i class="fa-square-check">:square-check:</i> | `"YWJjKys="` |

***

### Conversion Behavior

This function applies the following transformations:

| Base64 Character | Replaced With (Base64URL) |
| ---------------- | ------------------------- |
| `+`              | `-`                       |
| `/`              | `_`                       |
| `=`              | *(removed)*               |

***

### Example Usage

```js
async function() {
    let x = this.encodeBase64ToBase64Url("YWJjKys="); // Base64 of "abc++"
    return x; // → "YWJjKys"
}
```

This converts the Base64 string `"YWJjKys="` into a **Base64URL-safe** format by removing `=` padding and replacing special characters.

***

### Use Cases

* Encode payloads or claims for **JWT (JSON Web Token)**
* Safely pass encoded values in **URLs or query parameters**
* Normalize Base64 data for systems that **reject or mishandle special characters**

***

### Notes

* The input must be a valid **Base64-encoded** string. This function does not encode raw values — it **only converts** Base64 → Base64URL.
* For Base64 encoding of raw input, use native methods or pre-process before using this function.
* The resulting output will contain only **URL-safe characters**.

***

### Summary

`this.encodeBase64ToBase64Url` allows you to convert standard Base64 strings into the Base64URL format required by web standards like JWT. This ensures compatibility in environments where Base64 special characters can cause issues.


---

# Agent Instructions: 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.jentis.com/developer-guide/variables/server-side-variables/public-function-scope/encodebase64tobase64url.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.
