TypeScript SDK
Quickstart
Get started with the post2all SDK in under 5 minutes.
Prerequisites
- A post2all account with an active subscription that includes API access
- Node.js 20 or later
- An API key from Settings → API Keys in your workspace
1. Install
pnpm add @post2all/sdk2. Get Your API Key
Create an API key in your post2all workspace under Settings → API Keys. Each key is scoped to a specific organization. The key prefix is amp_.
3. Initialize the Client
import { Post2allClient } from "@post2all/sdk"
const client = new Post2allClient({
apiKey: process.env.POST2ALL_API_KEY,
})Store your API key in an environment variable — never hardcode it.
4. List Your Connected Accounts
Before creating posts, discover which social accounts are available:
const { accounts } = await client.listAccounts()
for (const account of accounts) {
console.log(`${account.platform}: ${account.username}`)
console.log(` Supports: text=${account.supportedPostTypes.text}, image=${account.supportedPostTypes.image}, video=${account.supportedPostTypes.video}`)
}5. Create Your First Post
Publish Immediately
const { post } = await client.createPost({
type: "text",
socialAccountIds: ["acc_123"],
content: "Hello from the SDK!",
// No status means publish immediately (defaults to "scheduled" with now)
})Schedule for Later
const { post } = await client.createPost({
type: "text",
socialAccountIds: ["acc_123"],
content: "Scheduled post",
status: "scheduled",
scheduledAt: "2026-06-20T09:00:00Z",
})Save as Draft
const { post } = await client.createPost({
type: "text",
socialAccountIds: ["acc_123"],
content: "Draft content",
status: "draft",
})Image Post with Local Files
const { post } = await client.createPost({
type: "image",
socialAccountIds: ["acc_123"],
content: "Check out this photo",
mediaPaths: ["./photo1.jpg", "./photo2.jpg"],
})Media files are read from disk and included directly in the request — no separate upload step needed.
6. Error Handling
Wrap API calls in try/catch and use Post2allApiError to handle failures:
import { Post2allClient, Post2allApiError } from "@post2all/sdk"
const client = new Post2allClient({
apiKey: process.env.POST2ALL_API_KEY,
})
try {
const { post } = await client.createPost({
type: "text",
socialAccountIds: ["acc_123"],
content: "Hello",
})
console.log(`Created post: ${post.id}`)
} catch (error) {
if (error instanceof Post2allApiError) {
console.error(`API error (${error.code}): ${error.message}`)
console.error(`HTTP status: ${error.status}`)
} else {
console.error("Unexpected error:", error)
}
}Next Steps
- See the API Reference for all available methods
- Use the CLI for interactive post management
- Check the REST API docs for raw HTTP usage