Resources

SDKs

Install and use the official Onepostly SDKs for Node.js and Python.

The TypeScript and Python SDKs are generated from the OpenAPI spec, so they cover every route in the API Reference with typed requests and responses.

Prefer plain HTTP? Every example has a cURL tab. See Authentication.

LanguagePackageRuns on
TypeScript@onepostly/sdkNode.js 18+, browsers and edge, no dependencies
PythononepostlyPython 3.10+, every method async

Each API Reference group is one class, such as PostsApi or InboxApi. Method names follow the operation ids, so Create Post is createPost or create_post.

Node.js

npm install @onepostly/sdk

Create a Configuration with your API key and pass it to each API class you use. accessToken sends the key as Authorization: Bearer.

publish.ts
import { Configuration, PostsApi } from "@onepostly/sdk";

const config = new Configuration({ accessToken: process.env.ONEPOSTLY_API_KEY });
const posts = new PostsApi(config);

const created = await posts.createPost({
  createPostBody: {
    text: "Hello from Onepostly",
    accounts: [{ accountId: "acc_YOUR_X_ACCOUNT_ID" }],
  },
});

console.log(created.groupId, created.data[0]?.status);
DetailHow it works
ParametersOne object. The JSON body goes under its schema name, such as createPostBody
Return valueThe parsed body. …Raw methods, such as createPostRaw, add the Response
Per-request optionsThe second argument changes the fetch call, such as headers or signal
Base URLhttps://api.onepostly.com. Change it with basePath

Python

pip install onepostly

Create a Configuration with your API key, open an ApiClient with it, and pass that to each API class. access_token sends the key as Authorization: Bearer.

publish.py
import asyncio
import os

from onepostly import ApiClient, Configuration
from onepostly.api.posts_api import PostsApi


async def main() -> None:
    configuration = Configuration(access_token=os.environ["ONEPOSTLY_API_KEY"])
    async with ApiClient(configuration) as api_client:
        posts_api = PostsApi(api_client)
        created = await posts_api.create_post(
            create_post_body={
                "text": "Hello from Onepostly",
                "accounts": [{"accountId": "acc_YOUR_X_ACCOUNT_ID"}],
            },
        )
        print(created.group_id, created.data[0].status)


asyncio.run(main())
DetailHow it works
ParametersKeyword arguments. The body takes a model or a dict with API field names
Return valueA typed model with snake_case attributes, such as group_id
Status and headersCall the …_with_http_info variant of the method
Per-request options_headers adds headers, and _request_timeout sets a timeout
Base URLhttps://api.onepostly.com. Change it with host

Errors

Every non-2xx response raises an error with the HTTP status and the error body. Branch on its code, and log its requestId for support.

A non-2xx response throws a ResponseError, with the Response in response. A network failure throws a FetchError, with the cause in cause.

import { ResponseError } from "@onepostly/sdk";

try {
  await posts.createPost({ createPostBody: body });
} catch (error) {
  if (error instanceof ResponseError) {
    const { code, error: message, requestId } = await error.response.json();
    console.error(error.response.status, code, message, requestId);
  } else {
    throw error;
  }
}

Fields with listed values, such as status, can gain new ones. A new value does not break parsing, but your code must handle it. See Open Enums.

Retries

The SDKs never retry on their own. Retry a 429, a 5xx or a network failure yourself, and wait for Retry-After as shown in Handle 429 Responses.

To retry a POST safely, send an Idempotency-Key and reuse it for every attempt. A repeat then returns the first response. See Idempotent Requests.

import { randomUUID } from "node:crypto";

const idempotencyKey = randomUUID();

await posts.createPost({ idempotencyKey, createPostBody: body });

Pagination

Lists return data, nextCursor and hasMore. There is no paging helper, so pass nextCursor as cursor until hasMore is false. See Pagination.

let cursor: string | undefined;
do {
  const page = await posts.listPosts({ limit: 100, cursor });
  for (const post of page.data) console.log(post.id, post.status);
  cursor = page.hasMore ? (page.nextCursor ?? undefined) : undefined;
} while (cursor);

Webhooks

The SDKs do not verify webhook signatures. Use the Node.js and Python functions in Verify Signatures, and type your handler from the spec's webhooks section.