TypeScript
A typed client generated from the API contract.
@vojo/api-client is a typed client built on openapi-fetch. Its types are generated from the same contract as this reference, so a wrong path, parameter or field fails at compile time.
The client isn't published to npm yet. Until it's published, ask your Vojo contact for a copy, or generate your own types from the contract with
openapi-typescript.
Create a client
import { createVojoClient } from "@vojo/api-client";
const api = createVojoClient({
baseUrl: "https://api.vojo-media.com",
getToken: () => process.env.VOJO_KEY,
});| Option | What it does |
|---|---|
baseUrl |
The base URL. Use http://127.0.0.1:4020 for the mock server. |
getToken |
Returns your secret key or OAuth access token. Called on each request. |
getOrganisationId |
Returns the value for Vojo-Organisation. OAuth callers need it, and secret keys don't. |
version |
Pins Vojo-Version to a date. Leave it out to use the version pinned on your key or organisation. |
fetch |
Your own fetch, for example to add logging. |
Make a request
Each method takes a path from the contract. A response has either data or error.
import { VojoApiError } from "@vojo/api-client";
const { data, error } = await api.GET("/v1/screens/{screen_id}", {
params: { path: { screen_id: screenId } },
});
if (error) throw new VojoApiError(error);
console.log(data.data.name, data.data.last_evidence_at);VojoApiError wraps the problem response, which you can read from its problem property.
Page through a list
listAll follows the cursor for you, and stops with an error if the API ever returns a cursor it has already followed.
import { listAll } from "@vojo/api-client";
for await (const screen of listAll((cursor) =>
api.GET("/v1/screens", { params: { query: { cursor, limit: 100 } } }),
)) {
console.log(screen.name);
}More languages
Any HTTP client works with the API. Every reference page has a curl example you can adapt, and Receive webhooks has signature verification in Node.js, Python and Go.