TypeScript SDK

API Reference

Complete method reference for the Post2allClient class.

Constructor

import { Post2allClient } from "@post2all/sdk"

const client = new Post2allClient({
  apiKey: "amp_your_api_key",     // required
  baseUrl: "https://www.post2all.com/api/v1", // optional, this is the default
  fetchImplementation: fetch,      // optional, custom fetch for testing
})
OptionTypeRequiredDefault
apiKeystringYes
baseUrlstringNohttps://www.post2all.com/api/v1
fetchImplementationtypeof fetchNoGlobal fetch

The API key is sent as the x-api-key header on every request.


listAccounts()

Returns all connected social media accounts for your organization.

const response = await client.listAccounts()

Returns: ListAccountsResponse

{
  accounts: {
    id: string
    platform: "twitter" | "linkedin" | "youtube" | "instagram" | "pinterest" | "threads"
    platformAccountId: string
    username: string | null
    displayName: string | null
    avatarUrl: string | null
    status: string
    supportedPostTypes: {
      text: boolean
      image: boolean
      video: boolean
    }
    createdAt: string
  }[]
}

createPost()

Creates a text, image, or video post. Supports draft, scheduled, and immediate publishing with inline media upload.

const response = await client.createPost({
  type: "text",
  socialAccountIds: ["acc_123", "acc_456"],
  content: "Hello world",
  status: "scheduled",
  scheduledAt: "2026-06-20T09:00:00Z",
  mediaPaths: ["./photo.jpg"],
  accountSettings: {
    acc_123: { caption: "Custom caption" },
  },
})

Input: CreatePostInput

FieldTypeRequiredDescription
type"text" | "image" | "video"YesPost content type
socialAccountIdsstring[]YesAccount IDs to post to (from listAccounts)
contentstringNoPost content text. Required for text posts
status"draft" | "scheduled"NoDefault: "scheduled" (publishes immediately if no scheduledAt)
scheduledAtstring (ISO 8601)NoSchedule date. Required if status is "scheduled"
mediaPathsstring[]NoLocal file paths for image/video posts
accountSettingsRecord<string, Record<string, unknown>>NoPer-account content overrides

Returns: CreatePostResponse

{
  post: {
    id: string
    type: string
    content: string | null
    status: string
    scheduledAt: string | null
    createdAt: string
    mediaCount?: number
    accountCount?: number
  }
}

Notes

  • Image/video posts require mediaPaths or content — provide at least one
  • Drafts don't trigger publishing and don't count against limits
  • Scheduled without scheduledAt publishes immediately (API defaults to now)
  • Media files are read from local disk and uploaded inline in the request

listPosts()

Lists posts with pagination and optional filters.

const response = await client.listPosts({
  page: 1,
  limit: 20,
  status: "published",
  type: "text",
})

Input: ListPostsInput (all optional)

FieldTypeDescription
pagenumberPage number (default: 1)
limitnumberItems per page (default: 20, max: 100)
status"draft" | "scheduled" | "published" | "partially_failed" | "failed"Filter by status
type"text" | "image" | "video"Filter by type

Returns: ListPostsResponse

{
  posts: {
    id: string
    type: string
    content: string | null
    status: string
    scheduledAt: string | null
    publishedAt: string | null
    createdAt: string
    accounts: {
      id: string | null
      platform: string
      username: string | null
      displayName: string | null
      disconnected: boolean
      status: string
      platformPostUrl: string | null
      error: string | null
    }[]
  }[]
  pagination: {
    page: number
    limit: number
    hasMore: boolean
  }
}

getPost()

Returns full details for a single post including per-account publish status.

const response = await client.getPost("post_abc")

Parameters: postId: string

Returns: GetPostResponse

{
  post: {
    id: string
    type: string
    content: string | null
    media?: { type: string, path: string }[]
    status: string
    scheduledAt: string | null
    publishedAt: string | null
    createdAt: string
    updatedAt: string | null
    accounts: {
      id: string | null
      platform: string
      platformAccountId: string | null
      username: string | null
      displayName: string | null
      avatarUrl: string | null
      disconnected: boolean
      status: string
      platformPostId: string | null
      platformPostUrl: string | null
      error: string | null
      publishedAt: string | null
    }[]
  }
}

updatePost()

Updates a draft or scheduled post. All fields are optional — only provided fields are updated.

const response = await client.updatePost("post_abc", {
  content: "Updated content",
  scheduledAt: "2026-06-21T10:00:00Z",
})

Parameters

ParamTypeDescription
postIdstringPost ID to update
inputUpdatePostInputFields to update

Input: UpdatePostInput (all optional)

FieldTypeDescription
type"text" | "image" | "video"New post type
contentstringNew content
socialAccountIdsstring[]New target accounts
status"draft" | "scheduled"New status
scheduledAtstring (ISO 8601)New schedule date
accountSettingsRecord<string, Record<string, unknown>>New per-account settings

Returns: UpdatePostResponse

{
  post: {
    id: string
    type: string
    content: string | null
    status: string
    scheduledAt: string | null
    publishedAt: string | null
    createdAt: string
    updatedAt: string | null
  }
}

Only draft or scheduled posts can be updated. Published posts are immutable.


deletePost()

Permanently deletes a post. Cancels any pending publish schedule and removes associated media.

const response = await client.deletePost("post_abc")

Parameters: postId: string

Returns: DeletePostResponse

{ success: true }

cancelPost()

Moves a scheduled post back to draft status. Cancels the pending publish trigger.

const response = await client.cancelPost("post_abc")

Parameters: postId: string

Returns: CancelPostResponse

{
  post: {
    id: string
    type: string
    content: string | null
    status: "draft"
    scheduledAt: string | null
    createdAt: string
    updatedAt: string | null
  }
}

Only works for posts with status: "scheduled".


Error Handling

All methods throw Post2allApiError on non-2xx responses:

import { Post2allApiError } from "@post2all/sdk"

try {
  await client.createPost({ ... })
} catch (error) {
  if (error instanceof Post2allApiError) {
    error.status   // HTTP status code
    error.code     // Error code (e.g., "INVALID_API_KEY")
    error.message  // Human-readable message
    error.details  // Raw API error body
  }
}
CodeHTTPDescription
INVALID_API_KEY401Missing or invalid API key
EXPIRED_API_KEY401API key has expired
RATE_LIMITED429Too many requests
FORBIDDEN403Key doesn't have org access
PLAN_UPGRADE_REQUIRED403Plan doesn't include API access
INVALID_REQUEST400Malformed body or missing fields
INVALID_ACCOUNTS400Account IDs don't belong to your org
UNSUPPORTED_MEDIA400File type not image/* or video/*
POST_NOT_FOUND404Post ID not found
INTERNAL_ERROR500Server error

CLI

The post2all CLI is built on this SDK. Install it with:

pnpm add -g @post2all/cli
# Authenticate
post2all config set-key amp_xxx

# List accounts
post2all accounts

# Create a post
post2all post create \
  --type text \
  --accounts acc_1,acc_2 \
  --content "Hello from CLI"

# List posts
post2all posts --status scheduled

# Cancel a scheduled post
post2all post cancel post_abc

See the CLI repository for full documentation and the SKILL.md for AI agent integration.

On this page