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

# MCP execute examples for media & tweet posting

> Copy MCP execute examples that post tweets with media, upload media for DMs, download media, and build a gallery link through the Xquik API sandbox for agents.

> For the complete documentation index, see [llms.txt](https://docs.xquik.com/llms.txt).

Run these inside the [`execute` tool](https://docs.xquik.com/mcp/tools#execute). Each example is one sandbox call.

## Examples

> Post an X (Twitter) tweet or reply with public media URLs (credits required)

Hosted MCP injects the required `Idempotency-Key`. Direct REST callers must
supply it themselves.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const body = {
    account: "myxhandle",
    text: "Launch media is ready",
    reply_to_tweet_id: "1893456789012345678",
    media: ["https://example.com/product-demo.mp4"],
  };

  const { result } = await xquik.request({
    path: "/api/v1/x/tweets",
    method: "POST",
    body,
  });

  return {
    source: "xquik_mcp",
    job: "tweet_write",
    status: result.status,
    terminal: result.terminal,
    safe_to_retry: result.safe_to_retry,
    write_action_id: result.id,
    request_hash: result.request.hash,
    tweet_id: result.result?.id ?? result.tweet_id ?? null,
    poll: result.terminal ? null : result.status_url,
    account: body.account,
    reply_to_tweet_id: body.reply_to_tweet_id,
    media: body.media,
    charged: result.billing.charged,
    charged_credits: result.billing.charged_credits,
  };
};
```

> Upload media for a DM (credits required)

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const account = "myxhandle";
  const user_id = "44196397";
  const source_url = "https://example.com/image.png";

  const { result: media } = await xquik.request({
    path: "/api/v1/x/media",
    method: "POST",
    body: {
      account,
      url: source_url,
    },
  });

  const { result: dm } = await xquik.request({
    path: `/api/v1/x/dm/${user_id}`,
    method: "POST",
    body: {
      account,
      text: "Here is the asset",
      media_ids: [media.media_id],
    },
  });

  return {
    source: "xquik_mcp",
    job: "dm_media",
    status: "sent",
    user_id,
    account,
    source_url,
    media_id: media.media_id,
    media_url: media.media_url,
    message_id: dm.message_id,
  };
};
```

Store `message_id` with the uploaded `media_id`. Keep full DM bodies out of
shared MCP outputs. Return IDs, status, media references, and source filenames
instead. Leave `reply_to_message_id` unset because the DM send endpoint rejects
reply threading.

> Download media and get gallery link (credits required)

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const tweet_input = "1234567890";
  const { result: download } = await xquik.request({
    path: "/api/v1/x/media/download",
    method: "POST",
    body: { tweetInput: tweet_input },
  });

  return {
    source: "xquik_mcp",
    job: "media_download",
    mode: "single",
    tweet_input,
    tweet_id: download.tweet_id,
    gallery_url: download.gallery_url,
    cache_hit: download.cache_hit,
    note: "Store gallery_url as the saved media gallery. It is not an uploaded media_id for DMs.",
  };
};
```

> Bulk download combines search and download.

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/bash.json","/languages/csharp.json","/languages/go.json","/languages/java.json","/languages/javascript.json","/languages/kotlin.json","/languages/php.json","/languages/python.json","/languages/ruby.json","/languages/typescript.json"]}}
async () => {
  const query = "from:berktavsan has:videos";
  const { result: search } = await xquik.request({
    path: "/api/v1/x/tweets/search",
    query: { q: query },
  });
  if (!search.tweets?.length) {
    return {
      source: "xquik_mcp",
      job: "bulk_media_download",
      status: "empty",
      query,
    };
  }

  const tweetIds = search.tweets.map((t) => t.id).slice(0, 50);
  const { result: download } = await xquik.request({
    path: "/api/v1/x/media/download",
    method: "POST",
    body: { tweetIds },
  });

  return {
    source: "xquik_mcp",
    job: "bulk_media_download",
    status: "ready",
    query,
    tweet_ids: tweetIds,
    gallery_url: download.gallery_url,
    total_tweets: download.total_tweets,
    total_media: download.total_media,
  };
};
```

## Next steps

* [MCP tools](https://docs.xquik.com/mcp/tools.md)
* [MCP overview](https://docs.xquik.com/mcp/overview.md)


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