> 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.

# Provision up to 1000 tokens

POST https://api.ocpplab.io/emsp/tokens/bulk
Content-Type: application/json

The batch is validated and created as a whole. With ``auto_activate`` each token is pushed in turn; a failed push is listed and that token stays PROVISIONED.

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

## Authentication

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

## Request

### 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 TokenBulkCreate.

- `tokens` (list of TokenCreate, required)

## Response

### 202

How many tokens were provisioned and activated, and which pushes failed.

- `provisioned` (integer, required)
- `activated` (integer, required)
- `failures` (list of TokenFailureItem, required)

## Errors

### 401 Unauthorized Error

Missing or invalid Bearer token

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

### 409 Conflict Error

A token in the batch already exists

- `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

### TokenCreate

Body of POST /emsp/tokens and one item of POST /emsp/tokens/bulk.

- `uid` (string, required)
- `type` (enum, required)
  - Allowed values: `AD_HOC_USER`, `APP_USER`, `OTHER`, `RFID`
- `contract_id` (string, required)
- `issuer` (string, required)
- `visual_number` (string, optional, nullable)
- `group_id` (string, optional, nullable)
- `whitelist` (enum, optional, nullable, default: ALLOWED)
  - Allowed values: `ALWAYS`, `ALLOWED`, `ALLOWED_OFFLINE`, `NEVER`
- `language` (string, optional, nullable)
- `valid_from` (datetime, optional, nullable)
- `valid_until` (datetime, optional, nullable)
- `country_code` (string, optional, nullable)
- `party_id` (string, optional, nullable)
- `ocpi_version` (enum, optional, nullable, default: 221)
  - Allowed values: `211`, `221`, `230`
- `metadata` (map from string to any, optional, nullable)
- `auto_activate` (boolean, optional, nullable, default: false)

### TokenFailureItem

A bulk token that stayed PROVISIONED because activation failed.

- `uid` (string, required)
- `error` (string, required)

### 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
{
  "tokens": [
    {
      "uid": "04A2B3C4D5E6F7",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0001",
      "language": "nl",
      "metadata": {
        "driver_id": "drv-123"
      },
      "auto_activate": true
    },
    {
      "uid": "04A2B3C4D5E6F8",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0002",
      "language": "nl",
      "metadata": {
        "driver_id": "drv-123"
      },
      "auto_activate": true
    }
  ]
}
```

**Response**

```json
{
  "provisioned": 2,
  "activated": 1,
  "failures": [
    {
      "uid": "04A2B3C4D5E6F8",
      "error": "partner push failed"
    }
  ]
}
```

**SDK Code**

```python
import requests

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

payload = { "tokens": [
        {
            "uid": "04A2B3C4D5E6F7",
            "type": "RFID",
            "contract_id": "NL-OCP-C12345678-X",
            "issuer": "OCPPLab Mobility",
            "visual_number": "OCP-0001",
            "language": "nl",
            "metadata": { "driver_id": "drv-123" },
            "auto_activate": True
        },
        {
            "uid": "04A2B3C4D5E6F8",
            "type": "RFID",
            "contract_id": "NL-OCP-C12345678-X",
            "issuer": "OCPPLab Mobility",
            "visual_number": "OCP-0002",
            "language": "nl",
            "metadata": { "driver_id": "drv-123" },
            "auto_activate": True
        }
    ] }
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/bulk';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': '5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: '{"tokens":[{"uid":"04A2B3C4D5E6F7","type":"RFID","contract_id":"NL-OCP-C12345678-X","issuer":"OCPPLab Mobility","visual_number":"OCP-0001","language":"nl","metadata":{"driver_id":"drv-123"},"auto_activate":true},{"uid":"04A2B3C4D5E6F8","type":"RFID","contract_id":"NL-OCP-C12345678-X","issuer":"OCPPLab Mobility","visual_number":"OCP-0002","language":"nl","metadata":{"driver_id":"drv-123"},"auto_activate":true}]}'
};

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/bulk"

	payload := strings.NewReader("{\n  \"tokens\": [\n    {\n      \"uid\": \"04A2B3C4D5E6F7\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0001\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    },\n    {\n      \"uid\": \"04A2B3C4D5E6F8\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0002\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    }\n  ]\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/bulk")

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  \"tokens\": [\n    {\n      \"uid\": \"04A2B3C4D5E6F7\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0001\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    },\n    {\n      \"uid\": \"04A2B3C4D5E6F8\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0002\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    }\n  ]\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/bulk")
  .header("Idempotency-Key", "5d1f7c2e-8b3a-4e6f-9c0d-1a2b3c4d5e6f")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"tokens\": [\n    {\n      \"uid\": \"04A2B3C4D5E6F7\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0001\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    },\n    {\n      \"uid\": \"04A2B3C4D5E6F8\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0002\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.ocpplab.io/emsp/tokens/bulk', [
  'body' => '{
  "tokens": [
    {
      "uid": "04A2B3C4D5E6F7",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0001",
      "language": "nl",
      "metadata": {
        "driver_id": "drv-123"
      },
      "auto_activate": true
    },
    {
      "uid": "04A2B3C4D5E6F8",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0002",
      "language": "nl",
      "metadata": {
        "driver_id": "drv-123"
      },
      "auto_activate": true
    }
  ]
}',
  '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/bulk");
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  \"tokens\": [\n    {\n      \"uid\": \"04A2B3C4D5E6F7\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0001\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    },\n    {\n      \"uid\": \"04A2B3C4D5E6F8\",\n      \"type\": \"RFID\",\n      \"contract_id\": \"NL-OCP-C12345678-X\",\n      \"issuer\": \"OCPPLab Mobility\",\n      \"visual_number\": \"OCP-0002\",\n      \"language\": \"nl\",\n      \"metadata\": {\n        \"driver_id\": \"drv-123\"\n      },\n      \"auto_activate\": true\n    }\n  ]\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 = ["tokens": [
    [
      "uid": "04A2B3C4D5E6F7",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0001",
      "language": "nl",
      "metadata": ["driver_id": "drv-123"],
      "auto_activate": true
    ],
    [
      "uid": "04A2B3C4D5E6F8",
      "type": "RFID",
      "contract_id": "NL-OCP-C12345678-X",
      "issuer": "OCPPLab Mobility",
      "visual_number": "OCP-0002",
      "language": "nl",
      "metadata": ["driver_id": "drv-123"],
      "auto_activate": true
    ]
  ]] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.ocpplab.io/emsp/tokens/bulk")! 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()
```