> For the complete documentation index, see [llms.txt](https://docs.miatel.com/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.miatel.com/api/url-shortener/authorization.md). Agents can also search and read this documentation through its [MCP server](https://docs.miatel.com/api/~gitbook/mcp).

# Authorization

Get an access token for the URL shortener.

### Authorization

Before requesting an access token:

1. Register for a [Miatel personal account](https://app.miatel.com/) if you do not have one, then sign in.
2. Open [Access to API](https://app.miatel.com/access_to_api) in your personal account.
3. Create an app key with the `shortener_link` scope.
4. Copy and securely save the `client_creds` value when the key is created. Miatel displays it only once. Set `MIATEL_CLIENT_CREDS` to that value exactly as issued.

Exchange the app key for an access token as shown below.

#### Request Example

```bash
curl --request POST 'https://app.miatel.com/oauth/token' \
  --header "Authorization: Basic $MIATEL_CLIENT_CREDS" \
  --header 'Content-Type: application/json' \
  --header 'Accept: application/json' \
  --data '{"grant_type":"client_credentials","scope":"shortener_link"}'
```

#### Response

Use the returned `access_token` in the `Authorization: Bearer <access_token>` header. The token expires after 3600 seconds. Exchange the same app key for a new token when needed.

{% hint style="info" %}
Use the Bearer token when calling the shortener API. Keep your app key credentials on your server.
{% endhint %}

### Usage limits and retries

All endpoints share a limit of 50 requests per second from one IP address. Up to 50 more requests wait in a queue and are served at that rate, which can increase response time. Clients behind the same IP address share the limit. For large batches, use [Create links in bulk](https://docs.miatel.com/api/url-shortener/create-links-in-bulk), with up to 1000 links per request.

When the queue is full, nginx returns `429 Too Many Requests` before the request reaches the API. The request has changed nothing. Its response body is outside the API's JSON and CBOR error format: handle it by HTTP status. Wait at least one second before retrying, and increase the wait after each further 429.

After a timeout or a `5XX` response, the result is unknown. There is no idempotency key. Read requests, [Search links](https://docs.miatel.com/api/url-shortener/search-links) and [Generate a short code](https://docs.miatel.com/api/url-shortener/generate-a-short-code) can be repeated. PATCH can be repeated with the same values. A repeated DELETE can return 404 because the first attempt already deleted the object.

Do not automatically repeat link creation with generated codes: it can create duplicate links. For recoverable creation, keep an explicit `shortcode` and reuse the same request body. See the retry instructions on [Shorten a URL](https://docs.miatel.com/api/url-shortener/shorten-a-url#recover-after-a-timeout), [Create links in bulk](https://docs.miatel.com/api/url-shortener/create-links-in-bulk#recover-after-a-timeout) and [Create a tag](https://docs.miatel.com/api/url-shortener/create-a-tag#recover-after-a-timeout). When recovering after a conflict, check that the located object matches the request you intended.

## Exchange an app key for an access token

> OAuth 2.0 client credentials (RFC 6749 4.4). Send the key as HTTP Basic only, \`Authorization: Basic \<client\_creds>\`\
> with \`client\_creds\` exactly as received on creation: \`client\_id\` and \`client\_secret\` in the body are ignored\
> and return 401.\
> \
> The body may be empty. \`scope\` narrows the token to a part of the key's scopes: the token gets the requested\
> scopes the key has, the others are dropped, and the response \`scope\` lists what was granted.\
> \
> A revoked or expired key gets no new tokens, a token already issued works until it expires.<br>

````json
{"openapi":"3.1.2","info":{"title":"Miatel Client API","version":"1.0.0"},"tags":[{"name":"authorization","description":"## Authorization\n\nBefore requesting an access token:\n\n1. Register for a [Miatel personal account](https://app.miatel.com/) if you do not have one, then sign in.\n2. Open [Access to API](https://app.miatel.com/access_to_api) in your personal account.\n3. Create an app key with the `shortener_link` scope.\n4. Copy and securely save the `client_creds` value when the key is created. Miatel displays it only once. Set `MIATEL_CLIENT_CREDS` to that value exactly as issued.\n\nExchange the app key for an access token as shown below.\n\n### Request Example\n\n```bash\ncurl --request POST 'https://app.miatel.com/oauth/token' \\\n  --header \"Authorization: Basic $MIATEL_CLIENT_CREDS\" \\\n  --header 'Content-Type: application/json' \\\n  --header 'Accept: application/json' \\\n  --data '{\"grant_type\":\"client_credentials\",\"scope\":\"shortener_link\"}'\n```\n\n### Response\n\nUse the returned `access_token` in the `Authorization: Bearer <access_token>` header. The token expires after 3600 seconds. Exchange the same app key for a new token when needed.\n\n{% hint style=\"info\" %}\nUse the Bearer token when calling the shortener API. Keep your app key credentials on your server.\n{% endhint %}\n\n## Usage limits and retries\n\nAll endpoints share a limit of 50 requests per second from one IP address. Up to 50 more requests wait in a queue and are served at that rate, which can increase response time. Clients behind the same IP address share the limit. For large batches, use [Create links in bulk](https://docs.miatel.com/api/url-shortener/create-links-in-bulk), with up to 1000 links per request.\n\nWhen the queue is full, nginx returns `429 Too Many Requests` before the request reaches the API. The request has changed nothing. Its response body is outside the API's JSON and CBOR error format: handle it by HTTP status. Wait at least one second before retrying, and increase the wait after each further 429.\n\nAfter a timeout or a `5XX` response, the result is unknown. There is no idempotency key. Read requests, [Search links](https://docs.miatel.com/api/url-shortener/search-links) and [Generate a short code](https://docs.miatel.com/api/url-shortener/generate-a-short-code) can be repeated. PATCH can be repeated with the same values. A repeated DELETE can return 404 because the first attempt already deleted the object.\n\nDo not automatically repeat link creation with generated codes: it can create duplicate links. For recoverable creation, keep an explicit `shortcode` and reuse the same request body. See the retry instructions on [Shorten a URL](https://docs.miatel.com/api/url-shortener/shorten-a-url#recover-after-a-timeout), [Create links in bulk](https://docs.miatel.com/api/url-shortener/create-links-in-bulk#recover-after-a-timeout) and [Create a tag](https://docs.miatel.com/api/url-shortener/create-a-tag#recover-after-a-timeout). When recovering after a conflict, check that the located object matches the request you intended."}],"servers":[{"url":"https://app.miatel.com"}],"security":[{"basicAuth":[]}],"components":{"securitySchemes":{"basicAuth":{"type":"http","scheme":"basic","description":"App key, `client_id` as the username and `client_secret` as the password. `client_creds` returned on creation\nis already `base64(client_id:client_secret)`\n"}},"schemas":{"TokenRequest":{"type":"object","properties":{"grant_type":{"type":"string","enum":["client_credentials"],"default":"client_credentials","description":"Optional, `client_credentials` by default"},"scope":{"type":"string","description":"Space-separated scopes to narrow the token to, all scopes of the key if omitted. Scopes the key\ndoes not have and unknown names are dropped\n"}}},"TokenResponse":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","description":"Opaque, the format may change"},"token_type":{"type":"string","enum":["Bearer"]},"expires_in":{"type":"integer","description":"Token lifetime in seconds"},"scope":{"type":"string","description":"Space-separated scopes actually granted to the token"}}},"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"string","description":"RFC 6749 error code on `/oauth/token`. On other endpoints, a short message that may change:\nrely on the HTTP status there. Errors without a specific message carry the HTTP status text,\nsuch as `Bad Request` or `Conflict`\n"},"error_description":{"type":"string","description":"On `/oauth/token`, a description for developers that may change. On other endpoints, only when a\nrequest breaks a constraint of the data (400, 409): the name of that constraint, such as\n`shortcode_format` or `tag_customer_id_name_unique`. The names are listed with the responses\n"}}}},"headers":{"NoStore":{"schema":{"type":"string"}},"NoCache":{"schema":{"type":"string"}}},"responses":{"TooManyRequests":{"description":"More than 50 requests per second from this IP address, and the queue of 50 more is full. nginx rejects\nthe request before the API, so nothing is changed and the request can be repeated after a pause of at least\na second. The body comes from nginx and is not part of this API: rely on the status code\n"}}},"paths":{"/oauth/token":{"post":{"tags":["authorization"],"operationId":"createToken","summary":"Exchange an app key for an access token","description":"OAuth 2.0 client credentials (RFC 6749 4.4). Send the key as HTTP Basic only, `Authorization: Basic <client_creds>`\nwith `client_creds` exactly as received on creation: `client_id` and `client_secret` in the body are ignored\nand return 401.\n\nThe body may be empty. `scope` narrows the token to a part of the key's scopes: the token gets the requested\nscopes the key has, the others are dropped, and the response `scope` lists what was granted.\n\nA revoked or expired key gets no new tokens, a token already issued works until it expires.\n","requestBody":{"required":false,"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/TokenRequest"}},"application/json":{"schema":{"$ref":"#/components/schemas/TokenRequest"}}}},"responses":{"200":{"description":"Token issued","headers":{"Cache-Control":{"$ref":"#/components/headers/NoStore"},"Pragma":{"$ref":"#/components/headers/NoCache"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TokenResponse"}}}},"400":{"description":"Invalid request","headers":{"Cache-Control":{"$ref":"#/components/headers/NoStore"},"Pragma":{"$ref":"#/components/headers/NoCache"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Missing or malformed client credentials","headers":{"WWW-Authenticate":{"schema":{"type":"string"}},"Cache-Control":{"$ref":"#/components/headers/NoStore"},"Pragma":{"$ref":"#/components/headers/NoCache"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"406":{"description":"`Accept` does not allow `application/json`. The body is empty"},"429":{"$ref":"#/components/responses/TooManyRequests"},"5XX":{"description":"Server error, retry later","headers":{"Cache-Control":{"$ref":"#/components/headers/NoStore"},"Pragma":{"$ref":"#/components/headers/NoCache"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
````


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.miatel.com/api/url-shortener/authorization.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
