> For the complete documentation index, see [llms.txt](https://docs.floral.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.floral.fun/api-v2/v2-integration-examples.md).

# Integration examples

These examples need an app token. See [Get an app token](/authentication/floral-connect.md#get-an-app-token).

```javascript
const API = "https://api.floral.fun/v2";
const headers = { Authorization: `Bearer ${appToken}` };

// Follows every page. A short or empty page doesn't mean the end.
async function* readAll(path) {
  let cursor = null;
  do {
    const url = new URL(`${API}${path}`);
    if (cursor) url.searchParams.set("cursor", cursor);
    const response = await fetch(url, { headers });
    if (response.status === 429) {
      await new Promise((r) => setTimeout(r, Number(response.headers.get("retry-after")) * 1000));
      continue;
    }
    if (!response.ok) throw new Error(`Floral returned ${response.status}`);
    const page = await response.json();
    yield* page.data;
    cursor = page.next_cursor;
  } while (cursor);
}
```

## Measure discussion of a project

Track public volume for a hashtag, leaving out bots:

```javascript
const response = await fetch(`${API}/analytics/hashtags/floral?interval=day&exclude_bots=true`, { headers });
const { activity } = await response.json();
for (const day of activity) console.log(day.at, day.posts, day.unique_authors);
```

Read individual posts with search:

```javascript
for await (const post of readAll("/search/posts?hashtag=floral&from=2026-11-01T00:00:00Z")) {
  if (post.quality.author_account_age_days < 7) continue; // your own rule
  console.log(post.url, post.likes_count);
}
```

## Check a creator's activity

```javascript
const profile = await (await fetch(`${API}/users/@alice`, { headers })).json();
for await (const post of readAll(`/users/${profile.id}/activity?type=original,quote&from=2026-11-01T00:00:00Z`)) {
  console.log(post.created_at, post.likes_count);
}
```

An account can go private at any time. Treat `403 visibility_restricted` as "stop showing this", and remove what you've stored.

## Run a social quest

V2 helps you set up and monitor campaigns. To decide whether a user completed one, keep using [`POST /v1/quests/verify`](/api-reference/verification.md), which works from the user's consent and issues a receipt.

```javascript
// Is this post a usable target? A 404 means it isn't public.
const target = await fetch(`${API}/posts/${postId}/engagement`, { headers });
if (target.status === 404) throw new Error("Pick a public post");

// See how the campaign is going.
const { likes, reposts } = await (await fetch(`${API}/analytics/posts/${postId}?interval=hour`, { headers })).json();
```

## Keep a copy up to date

With approval, register a [webhook](/api-v2/v2-webhooks-and-bulk.md) and catch up with bulk reading after any downtime:

```javascript
async function handleEvent(event) {
  if (await alreadyProcessed(event.id)) return;
  switch (event.type) {
    case "post.created":
    case "reply.created":
    case "quote.created":
      await savePost(event.data.post);
      break;
    case "post.unavailable":
      await deletePost(event.data.post_id);
      break;
    case "user.restricted":
      await recheckUser(event.data.user_id); // Remove whatever you can no longer read.
      break;
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.floral.fun/api-v2/v2-integration-examples.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
