## URL Encoding of Query Parameters

When building GET API requests, query parameter values may contain special characters such as spaces, &, =, ?, (, ), *, %, and others.

These characters have specific meanings in URLs and can lead to incorrect request parsing if not properly encoded.

## Why encoding is important

URL encoding ensures that special characters are safely transmitted and correctly interpreted by the API.

Important
Encode only the query parameter values, not the entire URL.

### Common characters and their encoded forms

| **Character** | **URL Encoded Form** |
|  --- | --- |
| space | `%20` or `+` |
| `'` | `%27` |
| `"` | `%22` |
| `&` | `%26` |
| `(` | `%28` |
| `)` | `%29` |
| `*` | `%2A` |
| `%` | `%25` |
| `=` | `%3D` |


### Incorrect Example


```http
GET /intelligence/api/knowledge-models/km_id/data?filterExpr=status eq 'active' and department eq 'Sales & Marketing' and name eq 'John'
```

This fails because **`&` acts as a parameter separator** and spaces must be URL-encoded.

### Correct Example


```http
GET /intelligence/api/knowledge-models/km_id/data?filterExpr=status%20eq%20%27active%27%20and%20department%20eq%20%27Sales%20%26%20Marketing%27%20and%20name%20eq%20%27John%27
```

Here, the `filterExpr` value is URL-encoded:

- Spaces → `%20`
- `&` (ampersand) → `%26`
- `'` (single quote) → `%27`


Without encoding, `&` would be interpreted as a separator between query parameters, breaking the request. Encoding ensures that all characters are correctly interpreted as part of the filter expression.

## Encoding in your code

Use built-in URL encoding functions to ensure correct formatting of query parameter values.

Most programming languages provide built-in functions for URL encoding. The following examples show how to encode a string value before adding it to a request URL.

Note
Depending on the encoder, spaces may be encoded as `%20` or `+`. Both are valid in query strings.

### JavaScript

Use `encodeURIComponent()`.


```javascript
const filter = "name eq 'Sales & Marketing'";
const encodedFilter = encodeURIComponent(filter);

// Encoded result:
// name%20eq%20%27Sales%20%26%20Marketing%27
```

### Python

Use `urllib.parse.quote()`.


```python
from urllib.parse import quote

filter = "name eq 'Sales & Marketing'"
encoded_filter = quote(filter)

// Encoded result:
// name%20eq%20%27Sales%20%26%20Marketing%27
```

### Java

Use `URLEncoder.encode()`.


```java
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

String filter = "name eq 'Sales & Marketing'";
String encodedFilter = URLEncoder.encode(filter, StandardCharsets.UTF_8);

// Encoded result:
// name+eq+%27Sales+%26+Marketing%27
```

### C#

Use `HttpUtility.UrlEncode()` from `System.Web` or `WebUtility.UrlEncode()` from `System.Net`.


```csharp
using System.Net;

string filter = "name eq 'Sales & Marketing'";
string encodedFilter = WebUtility.UrlEncode(filter);

// Encoded result:
// name+eq+%27Sales+%26+Marketing%27
```

For quick tests, you can also use online URL encoder/decoder tools.

### Optional: Use OpenAPI-generated clients

If you are using an OpenAPI-generated client, query parameter encoding is typically handled automatically by the generated code or the underlying HTTP library.

In this case, you can pass the raw filter expression as a parameter filter, without manually encoding it.

#### Example:

`filterExpr`: "name eq 'Sales & Marketing'"

See available generators:
[https://openapi-generator.tech/docs/generators/](https://openapi-generator.tech/docs/generators/)