API

OpenAPI description

Overview

OpenAPI is a specification for describing REST API interfaces. The OpenAPI Specification (OAS) is both human and machine-readable.

The OpenAPI Description (OAD) represents a formal description of an API and is often published by a service provider as a JSON or YAML file. The description can be used to generate client libraries, documentation, and other tools.

See OpenAPI Specification v3.1.0 and OpenAPI Initiative for more information.

Yoco’s OpenAPI description

We provide a publicly accessible OpenAPI 3.1 description of our REST API at https://api.yoco.com/openapi.json.

Using the OpenAPI description

Because the OpenAPI description is machine-readable, there are many publicly available tools that can be used to generate client libraries, documentation, and test API integrations.

Here are some common use-cases:

Generating an API client using OpenAPI Generator

We recommend using OpenAPI Generator to generate client libraries.

1

Install using your preferred package manager:

$npm install @openapitools/openapi-generator-cli -g
2

Verify openapi-generator-cli is installed:

Command
$openapi-generator-cli version
Output
7.16.0
3

List all available generators:

Command
$openapi-generator-cli list
Output
The following generators are available:
CLIENT generators:
- ada
- android
- apex
- bash
- c
- clojure
...
4

Generate a client library for TypeScript:

$openapi-generator-cli generate -g typescript -o yoco-typescript-client -i https://api.yoco.com/openapi.json
5

The client library will be generated in the yoco-typescript-client directory.

6

View the generated README.md file for usage instructions.

Generating a Python API client using openapi-python-client

We recommend using openapi-python-client to generate a client library for Python. It is a more modern alternative that has strong typing, better support for async and leverages Pydantic for data models and validation.

1

Install openapi-python-client generator:

$pipx install openapi-python-client --include-deps
2

Generate the client from the OpenAPI description:

$openapi-python-client generate --url https://api.yoco.com/openapi.json
3

The client library will be generated in the yoco-api-client directory.

4

Make an API call using the generated client:

Please note that this is just an example and is not production-ready code. You should never store credentials as plain text in your code.

1from yoco_api_client import AuthenticatedClient
2from yoco_api_client.api.orders import list_orders_v1_orders_get
3from yoco_api_client.models import ErrorResponse, PaginatedResponseOrder
4
5client = AuthenticatedClient(
6 base_url="https://api.yoco.com",
7 token="ThisIsAnOAuthAccessToken"
8)
9
10with client as client:
11 response = list_orders_v1_orders_get.sync(client=client)
12
13 if isinstance(response, PaginatedResponseOrder):
14 print(f"Received paginated order response: ", response)
15
16 for order in response.data:
17 print(order.id)
18 elif isinstance(response, ErrorResponse):
19 raise Exception(f"Received HTTP status code {response.status}: {response.detail}")