> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ocpplab.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ocpplab.io/_mcp/server.

# Revoke a token

POST https://api.ocpplab.io/emsp/tokens/{token_id}/revoke
Content-Type: application/json

Final: any status except REVOKED. A token partners already have is pushed with ``valid: false`` first. If the push to roaming partners fails the call answers 502 and the token is left as it was; retry with the same Idempotency-Key.

Reference: https://docs.ocpplab.io/api-reference/emsp/tokens/revoke

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Path parameters

- `token_id` (integer, required) — The token's ``id``.

### Headers

- `Idempotency-Key` (string, required) — A unique key you choose for this call, e.g. a UUID. Retrying with the same key returns the first result instead of acting twice.

### Body (application/json)

This endpoint expects a TokenReason.

- `reason` (string, optional, nullable)

## Response

### 200

The token after the change.

- `id` (integer, required)
- `organization_id` (string, required)
- `uid` (string, required)
- `type` (TokenOutType, required)
- `contract_id` (string, required)
- `issuer` (string, required)
- `country_code` (string, required)
- `party_id` (string, required)
- `whitelist` (TokenOutWhitelist, required)
- `ocpi_version` (string, required)
- `status` (TokenOutStatus, required)
- `created_at` (datetime, required)
- `last_updated` (datetime, required)
- `visual_number` (string, optional, nullable)
- `group_id` (string, optional, nullable)
- `language` (string, optional, nullable)
- `valid_from` (datetime, optional, nullable)
- `valid_until` (datetime, optional, nullable)
- `metadata` (map from string to any, optional, nullable)
- `status_reason` (string, optional, nullable)
- `invalidated_at` (datetime, optional, nullable)

## Errors

### 400 Bad Request Error

Not allowed from the token's current status

- `detail` (string, required) — Human-readable error message returned by the API.

### 401 Unauthorized Error

Missing or invalid Bearer token

- `detail` (string, required) — Human-readable error message returned by the API.

### 404 Not Found Error

Token not found for your organization

- `detail` (string, required) — Human-readable error message returned by the API.

### 409 Conflict Error

Idempotency-Key already used for a different request

- `detail` (string, required) — Human-readable error message returned by the API.

### 422 Unprocessable Entity Error

The request does not match the schema

- `detail` (list of ValidationError, optional) — One entry per invalid field.

### 429 Too Many Requests Error

Gateway rate limit reached; retry after the given seconds

- `detail` (string, required) — Human-readable error message returned by the API.

### 502 Bad Gateway Error

Gateway unreachable, failing, or misconfigured

- `detail` (string, required) — Human-readable error message returned by the API.

### 504 Gateway Timeout Error

Gateway timed out

- `detail` (string, required) — Human-readable error message returned by the API.

## Types

### TokenOutType

### TokenOutWhitelist

### TokenOutStatus

### ValidationError

Why one field is invalid.

- `loc` (list of ValidationErrorLocItems, required) — Where the field is: ``body`` / ``query`` / ``path`` / ``header``, then its name.
- `msg` (string, required) — What is wrong, in English.
- `type` (string, required) — Machine-readable error code, e.g. ``missing``.
- `input` (any, optional) — The value that was sent.
- `ctx` (ValidationErrorCtx, optional) — Details of the rule that failed, e.g. `{"le": 200}`.

### ValidationErrorLocItems

### ValidationErrorCtx

Details of the rule that failed, e.g. `{"le": 200}`.

## Examples

**Request**

```json
{
  "reason": "Contract ended"
}
```

**Response**

```json
{
  "id": 77,
  "organization_id": "550e8400-e29b-41d4-a716-446655440000",
  "uid": "04A2B3C4D5E6F7",
  "type": "RFID",
  "contract_id": "NL-OCP-C12345678-X",
  "issuer": "OCPPLab Mobility",
  "country_code": "NL",
  "party_id": "OCP",
  "whitelist": "ALLOWED",
  "ocpi_version": "221",
  "status": "REVOKED",
  "created_at": "2026-09-30T10:00:00Z",
  "last_updated": "2026-09-30T10:00:00Z",
  "visual_number": "OCP-0001",
  "language": "nl",
  "metadata": {
    "driver_id": "drv-123"
  },
  "status_reason": "Contract ended",
  "invalidated_at": "2026-09-30T10:00:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.ocpplab.io/emsp/tokens/77/revoke"

payload = { "reason": "Contract ended" }
headers = {
    "Idempotency-Key": "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.ocpplab.io/emsp/tokens/77/revoke';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"reason":"Contract ended"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.ocpplab.io/emsp/tokens/77/revoke"

	payload := strings.NewReader("{\n  \"reason\": \"Contract ended\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f")
	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.ocpplab.io/emsp/tokens/77/revoke")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"reason\": \"Contract ended\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.ocpplab.io/emsp/tokens/77/revoke")
  .header("Idempotency-Key", "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"reason\": \"Contract ended\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.ocpplab.io/emsp/tokens/77/revoke', [
  'body' => '{
  "reason": "Contract ended"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => '5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.ocpplab.io/emsp/tokens/77/revoke");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f");
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"reason\": \"Contract ended\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Idempotency-Key": "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f",
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["reason": "Contract ended"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.ocpplab.io/emsp/tokens/77/revoke")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```