From code

Cotlet has no SDK to install. Your endpoints are plain HTTPS and JSON, so any HTTP client calls them with your API key.

Node.js

TypeScript

const headers = {
  Authorization: `Bearer ${process.env.COTLET_API_KEY}`,
  'Content-Type': 'application/json',
};
const res = await fetch('https://cotlet.dev/api/v1/custom/recent_bookings', { method: 'POST', headers, body: JSON.stringify({ limit: 5 }) });
let body = await res.json();
if (!res.ok) {
  // body.code says what went wrong; a link such as body.browser_url says where to fix it
  throw new Error(`${body.code}: ${body.message}`);
}
// 202: the run takes longer than 30 s, so ask its status_url until it ends
const statusUrl = body.status_url;
while (body.status === 'running') {
  await new Promise((r) => setTimeout(r, 5000));
  body = await (await fetch(statusUrl, { headers })).json();
}
if (body.status === 'failed' || body.status === 'expired') {
  throw new Error(JSON.stringify(body.error ?? body.status));
}
console.log(body.data);

Node.js 18 or newer, Bun and Deno have fetch built in.

Python

Python

import os
import time

import requests

headers = {"Authorization": f"Bearer {os.environ['COTLET_API_KEY']}"}
res = requests.post("https://cotlet.dev/api/v1/custom/recent_bookings", headers=headers, json={"limit": 5}, timeout=100)
body = res.json()
if not res.ok:
    raise RuntimeError(f"{body['code']}: {body['message']}")
# 202: the run takes longer than 30 s, so ask its status_url until it ends
status_url = body.get("status_url")
while body.get("status") == "running":
    time.sleep(5)
    body = requests.get(status_url, headers=headers, timeout=30).json()
if body.get("status") in ("failed", "expired"):
    raise RuntimeError(body.get("error") or body["status"])
print(body["data"])

Calls that take longer

An answer within 30 seconds comes in the same request, 200 with data. A longer run answers 202 with a status_url. The examples above ask it every 5 seconds until the status is succeeded, failed or expired, so they handle both answers.

Terminal

Terminal

curl -s -X POST https://cotlet.dev/api/v1/custom/recent_bookings \
  -H "Authorization: Bearer $COTLET_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"limit": 5}'

A 200 answer holds data. A 202 answer holds a status_url: call it with the same Authorization header until status is succeeded.

Your endpoints as OpenAPI 3.1, for Postman and code generators: https://cotlet.dev/api/v1/custom/openapi.json with the same key.

Sign in once. Your agent does the rest.

Sign up and add the apps you need. Free 7-day trial with 500 credits, no card needed.