> ## Documentation Index
> Fetch the complete documentation index at: https://info.bundle.social/llms.txt
> Use this file to discover all available pages before exploring further.

# Examples

> Working code, not pseudocode. Examples for schedulers, analytics dashboards, bulk uploaders, and webhook handlers, plus a GitHub repo and Postman collection.

We're actively building out a library of examples covering common use cases - schedulers, analytics dashboards, bulk uploaders, webhook handlers, and more. This section is growing, so check back often.

## Select A Channel After OAuth

For Facebook, Instagram through Facebook Login, LinkedIn, YouTube, and Google Business, OAuth alone is not enough. After the user connects, select the page, profile, channel, or location they want this team to use.

```ts theme={null}
await fetch("https://api.bundle.social/api/v1/social-account/set-channel", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.BUNDLE_API_KEY
  },
  body: JSON.stringify({
    teamId: "team_123",
    type: "FACEBOOK",
    channelId: "page_123"
  })
});
```

Use `refresh-channels` before showing a custom picker if your cached channel list may be stale.

```ts theme={null}
await fetch("https://api.bundle.social/api/v1/social-account/refresh-channels", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.BUNDLE_API_KEY
  },
  body: JSON.stringify({
    teamId: "team_123",
    type: "FACEBOOK"
  })
});
```

## Create A Scheduled Post

```ts theme={null}
await fetch("https://api.bundle.social/api/v1/post", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.BUNDLE_API_KEY
  },
  body: JSON.stringify({
    teamId: "team_123",
    title: "Launch post",
    status: "SCHEDULED",
    postDate: "2026-06-01T15:00:00.000Z",
    socialAccountTypes: ["FACEBOOK", "INSTAGRAM"],
    data: {
      FACEBOOK: {
        type: "POST",
        text: "We are live.",
        uploadIds: ["upload_image_123"]
      },
      INSTAGRAM: {
        type: "POST",
        text: "We are live.",
        uploadIds: ["upload_image_123"],
        altText: "Product dashboard screenshot"
      }
    }
  })
});
```

## Safe Retries With `referenceKey`

Set `referenceKey` to your own ID for the post (1-128 characters, trimmed). It's unique per organization among posts that aren't deleted, so a retry after a timeout can't create the post twice.

```ts theme={null}
const res = await fetch("https://api.bundle.social/api/v1/post", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.BUNDLE_API_KEY
  },
  body: JSON.stringify({
    teamId: "team_123",
    title: "Launch post",
    referenceKey: "campaign-42-launch",
    status: "SCHEDULED",
    postDate: "2026-06-01T15:00:00.000Z",
    socialAccountTypes: ["FACEBOOK"],
    data: {
      FACEBOOK: { type: "POST", text: "We are live." }
    }
  })
});

if (res.status === 409) {
  // Already created by an earlier attempt: fetch it instead.
  const post = await fetch(
    "https://api.bundle.social/api/v1/post/reference-key/campaign-42-launch",
    { headers: { "x-api-key": process.env.BUNDLE_API_KEY } }
  ).then((r) => r.json());
}
```

* Creating (or updating) a post with a key another post already uses returns `409` with `A post with this referenceKey already exists in this organization`.
* `GET /api/v1/post/reference-key/{referenceKey}` returns the post, like `GET /api/v1/post/{id}`. URL-encode the key if it has special characters.
* Once a post is deleted, its key can be used again.

## Fetch Raw Analytics

Raw analytics return the raw payload stored for the newest analytics snapshot. Availability depends on platform.

```ts theme={null}
const response = await fetch(
  "https://api.bundle.social/api/v1/analytics/social-account/raw?teamId=team_123&platformType=FACEBOOK",
  {
    headers: {
      "x-api-key": process.env.BUNDLE_API_KEY
    }
  }
);

const rawAnalytics = await response.json();
```

## Handle Post Webhooks

There is no separate `post.failed` event. Use `post.published` and inspect `data.status`.

```ts theme={null}
export async function handleWebhook(event: {
  type: string;
  data: { id: string; status?: string; errors?: unknown };
}) {
  if (event.type !== "post.published") return;

  if (event.data.status === "ERROR") {
    await markPostFailed(event.data.id, event.data.errors);
    return;
  }

  if (event.data.status === "POSTED") {
    await markPostPublished(event.data.id);
  }
}
```

## More Resources

> [card] [GitHub repo with examples](https://github.com/bundleglobal/bundlesocial-examples)

> [card] [Postman collection](https://www.postman.com/socialmediaapibundle/bundle-social-social-media-api/overview)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.