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

# Create CPO (durable)

POST https://host.com/ocpi/cpos
Content-Type: application/json

Kick off a full OCPI CPO in one call: network + locations + chargers + topology routing. Returns **202 Accepted** in under a second with the freshly minted Token A (so the eMSP peer can handshake immediately) and a `status_url`. The slow per-location / per-charger / ECS work runs as a durable Upstash Workflow with step-level retries. Poll `GET {status_url}` every 1-2s until `status == READY` (or `FAILED`).

Reference: https://docs.ocpplab.com/api-reference/ocpplab-gateway-api/ocpi/ocpi-cpos/create

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: OCPPLab SDK
  version: 1.0.0
paths:
  /ocpi/cpos:
    post:
      operationId: create
      summary: Create CPO (durable)
      description: >-
        Kick off a full OCPI CPO in one call: network + locations + chargers +
        topology routing. Returns **202 Accepted** in under a second with the
        freshly minted Token A (so the eMSP peer can handshake immediately) and
        a `status_url`. The slow per-location / per-charger / ECS work runs as a
        durable Upstash Workflow with step-level retries. Poll `GET
        {status_url}` every 1-2s until `status == READY` (or `FAILED`).
      tags:
        - subpackage_ocpiCpos
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '202':
          description: CPO provisioning accepted; poll status_url for progress
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CpoAcceptedResponse'
        '401':
          description: Missing or invalid bearer token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorResponse'
        '403':
          description: Insufficient permissions or missing required claims
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorResponse'
        '404':
          description: Unknown template slug
          content:
            application/json:
              schema:
                description: Any type
        '422':
          description: Invalid overrides or missing catalog entries
          content:
            application/json:
              schema:
                description: Any type
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HttpErrorResponse'
        '503':
          description: Namespace exhausted or workflow backend unavailable
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCpoRequest'
servers:
  - url: https://host.com
components:
  schemas:
    BundleRole:
      type: string
      enum:
        - cpo
        - emsp
      description: Role this CPO takes in OCPI roaming.
      title: BundleRole
    CreateCpoRequest:
      type: object
      properties:
        template:
          type: string
          description: Template slug. Use `GET /ocpi/cpos/templates` for the gallery.
        country_code:
          type: string
          description: ISO 3166-1 alpha-2 country code.
        party_id:
          type: string
          description: >-
            3-char OCPI party identifier. May be auto-mangled on collision if
            another CPO already holds this (country, party) under your org.
        name_prefix:
          type: string
          description: Human label prepended to every identity created under this CPO.
        role:
          $ref: '#/components/schemas/BundleRole'
        ocpi_version:
          type: string
          default: 2.2.1
          description: OCPI protocol version.
        seed:
          type:
            - integer
            - 'null'
          description: >-
            Optional deterministic seed. Same seed + same template =
            byte-identical output. Leave null for random (different each call).
        ttl_seconds:
          type:
            - integer
            - 'null'
          default: 3600
          description: >-
            Auto-destroy after N seconds (min 60s, max 7 days). Defaults to 3600
            (1 hour) so exploratory CPOs don't pile up. Pass an explicit `null`
            to opt out of auto-destroy.
        overrides:
          type:
            - object
            - 'null'
          additionalProperties:
            type: integer
          description: >-
            Template-specific overrides. Supported keys: `locations`,
            `chargers_per_location`. Values are bounded by each template's caps.
      required:
        - template
        - country_code
        - party_id
        - name_prefix
      description: |-
        Body for `POST /ocpi/cpos`.

        The template + party scope are the only required fields. Everything
        else has a sane default so a minimal body still yields a working CPO.
      title: CreateCpoRequest
    CpoPartyScope:
      type: object
      properties:
        country_code:
          type: string
        party_id:
          type: string
        role:
          type: string
      required:
        - country_code
        - party_id
        - role
      description: The OCPI party identity the new CPO occupies.
      title: CpoPartyScope
    CpoRoamHelper:
      type: object
      properties:
        credentials_payload:
          type: object
          additionalProperties:
            description: Any type
          description: Body the peer can POST to `/ocpi/2.2.1/credentials`.
        curl_snippet:
          type: string
          description: >-
            Shell-quoted curl invocation that runs the credentials handshake
            against this CPO. Safe to copy-paste.
      required:
        - credentials_payload
        - curl_snippet
      description: Pre-built eMSP helper payload so the peer can handshake in one paste.
      title: CpoRoamHelper
    CpoProvisioningStatus:
      type: string
      enum:
        - PENDING
        - PROVISIONING
        - READY
        - FAILED
      description: Durable provisioning states the status endpoint can report.
      title: CpoProvisioningStatus
    CpoAcceptedResponse:
      type: object
      properties:
        cpo_id:
          type: string
        party:
          $ref: '#/components/schemas/CpoPartyScope'
        name_prefix:
          type: string
        template:
          type: string
        template_version:
          type: integer
        token_a:
          type: string
          description: Freshly minted Token A. Returned here only; not echoed on GET.
        ocpi_peer_url:
          type: string
        roam_helper:
          oneOf:
            - $ref: '#/components/schemas/CpoRoamHelper'
            - type: 'null'
        workflow_run_id:
          type:
            - string
            - 'null'
          description: >-
            Internal provisioning run id. Opaque to clients; include it in bug
            reports when something goes wrong.
        status:
          $ref: '#/components/schemas/CpoProvisioningStatus'
        status_url:
          type: string
          description: GET here to poll provisioning state.
        destroy_url:
          type: string
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - cpo_id
        - party
        - name_prefix
        - template
        - template_version
        - token_a
        - ocpi_peer_url
        - status_url
        - destroy_url
      description: |-
        Shape returned by `POST /ocpi/cpos` (HTTP 202).

        Provisioning is async: the fast inline phase finished (network + Token A
        minted, CPO row marked PENDING), and the per-location/per-charger work
        runs as a durable Upstash Workflow. Poll ``status_url`` every 1-2s until
        ``status == READY`` (or FAILED).
      title: CpoAcceptedResponse
    HttpErrorResponse:
      type: object
      properties:
        detail:
          type: string
          description: Human-readable error message returned by the API.
      required:
        - detail
      description: Standard HTTP error payload returned by the API.
      title: HttpErrorResponse
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

```

## SDK Code Examples

```python
import requests

url = "https://host.com/ocpi/cpos"

payload = {
    "template": "small-urban-ac",
    "country_code": "FR",
    "party_id": "ABC",
    "name_prefix": "alice",
    "role": "cpo",
    "ocpi_version": "2.2.1",
    "seed": 42,
    "ttl_seconds": 7200,
    "overrides": {
        "chargers_per_location": 3,
        "locations": 2
    }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://host.com/ocpi/cpos';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"template":"small-urban-ac","country_code":"FR","party_id":"ABC","name_prefix":"alice","role":"cpo","ocpi_version":"2.2.1","seed":42,"ttl_seconds":7200,"overrides":{"chargers_per_location":3,"locations":2}}'
};

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://host.com/ocpi/cpos"

	payload := strings.NewReader("{\n  \"template\": \"small-urban-ac\",\n  \"country_code\": \"FR\",\n  \"party_id\": \"ABC\",\n  \"name_prefix\": \"alice\",\n  \"role\": \"cpo\",\n  \"ocpi_version\": \"2.2.1\",\n  \"seed\": 42,\n  \"ttl_seconds\": 7200,\n  \"overrides\": {\n    \"chargers_per_location\": 3,\n    \"locations\": 2\n  }\n}")

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

	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://host.com/ocpi/cpos")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"template\": \"small-urban-ac\",\n  \"country_code\": \"FR\",\n  \"party_id\": \"ABC\",\n  \"name_prefix\": \"alice\",\n  \"role\": \"cpo\",\n  \"ocpi_version\": \"2.2.1\",\n  \"seed\": 42,\n  \"ttl_seconds\": 7200,\n  \"overrides\": {\n    \"chargers_per_location\": 3,\n    \"locations\": 2\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://host.com/ocpi/cpos")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"template\": \"small-urban-ac\",\n  \"country_code\": \"FR\",\n  \"party_id\": \"ABC\",\n  \"name_prefix\": \"alice\",\n  \"role\": \"cpo\",\n  \"ocpi_version\": \"2.2.1\",\n  \"seed\": 42,\n  \"ttl_seconds\": 7200,\n  \"overrides\": {\n    \"chargers_per_location\": 3,\n    \"locations\": 2\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://host.com/ocpi/cpos', [
  'body' => '{
  "template": "small-urban-ac",
  "country_code": "FR",
  "party_id": "ABC",
  "name_prefix": "alice",
  "role": "cpo",
  "ocpi_version": "2.2.1",
  "seed": 42,
  "ttl_seconds": 7200,
  "overrides": {
    "chargers_per_location": 3,
    "locations": 2
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://host.com/ocpi/cpos");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"template\": \"small-urban-ac\",\n  \"country_code\": \"FR\",\n  \"party_id\": \"ABC\",\n  \"name_prefix\": \"alice\",\n  \"role\": \"cpo\",\n  \"ocpi_version\": \"2.2.1\",\n  \"seed\": 42,\n  \"ttl_seconds\": 7200,\n  \"overrides\": {\n    \"chargers_per_location\": 3,\n    \"locations\": 2\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "template": "small-urban-ac",
  "country_code": "FR",
  "party_id": "ABC",
  "name_prefix": "alice",
  "role": "cpo",
  "ocpi_version": "2.2.1",
  "seed": 42,
  "ttl_seconds": 7200,
  "overrides": [
    "chargers_per_location": 3,
    "locations": 2
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://host.com/ocpi/cpos")! 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()
```