> ## Documentation Index
> Fetch the complete documentation index at: https://x-preview-mintlify-7cae4884.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# X API v2 manage Posts quickstart

> Step-by-step quickstart for creating and deleting Posts with the X API v2 standard tier, including authentication, request payloads, and examples.

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

This guide walks you through creating and deleting Posts using the X API.

<Note>
  **Prerequisites**

  Before you begin, you'll need:

  * A [developer account](https://developer.x.com/en/portal/petition/essential/basic-info) with an approved App
  * User Access Tokens (OAuth 1.0a or OAuth 2.0 PKCE)
</Note>

***

## Create a Post

<Steps>
  <Step title="Prepare your request">
    The POST `/2/tweets` endpoint requires a JSON body with at least `text` or `media`:

    ```json theme={null}
    {
      "text": "Hello from the X API!"
    }
    ```
  </Step>

  <Step title="Send the request">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{"text": "Hello from the X API!"}'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Create a Post
      response = client.posts.create(text="Hello from the X API!")
      print(f"Created Post: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Create a Post
      const response = await client.posts.create({ text: "Hello from the X API!" });
      console.log(`Created Post: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Review the response">
    A successful response includes the new Post's `id` and `text`:

    ```json theme={null}
    {
      "data": {
        "id": "1445880548472328192",
        "text": "Hello from the X API!"
      }
    }
    ```
  </Step>
</Steps>

***

## Advanced examples

<AccordionGroup>
  <Accordion title="Reply to a Post">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "This is a reply!",
          "reply": {
            "in_reply_to_tweet_id": "1234567890"
          }
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Create a reply
      response = client.posts.create(
          text="This is a reply!",
          reply={"in_reply_to_tweet_id": "1234567890"}
      )
      print(f"Created reply: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Create a reply
      const response = await client.posts.create({
        text: "This is a reply!",
        reply: { inReplyToTweetId: "1234567890" },
      });
      console.log(`Created reply: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Quote a Post">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Check this out!",
          "quote_tweet_id": "1234567890"
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Quote a Post
      response = client.posts.create(
          text="Check this out!",
          quote_tweet_id="1234567890"
      )
      print(f"Created quote: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Quote a Post
      const response = await client.posts.create({
        text: "Check this out!",
        quoteTweetId: "1234567890",
      });
      console.log(`Created quote: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Post with media">
    First, upload media using the [Media Upload endpoint](/x-api/media/quickstart/media-upload-chunked), then reference the `media_id`:

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Photo of the day!",
          "media": {
            "media_ids": ["1234567890123456789"]
          }
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Post with media
      response = client.posts.create(
          text="Photo of the day!",
          media={"media_ids": ["1234567890123456789"]}
      )
      print(f"Created Post with media: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Post with media
      const response = await client.posts.create({
        text: "Photo of the day!",
        media: { mediaIds: ["1234567890123456789"] },
      });
      console.log(`Created Post with media: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Post with poll">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "What is your favorite color?",
          "poll": {
            "options": ["Red", "Blue", "Green", "Yellow"],
            "duration_minutes": 1440
          }
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Post with poll
      response = client.posts.create(
          text="What is your favorite color?",
          poll={"options": ["Red", "Blue", "Green", "Yellow"], "duration_minutes": 1440}
      )
      print(f"Created poll: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Post with poll
      const response = await client.posts.create({
        text: "What is your favorite color?",
        poll: { options: ["Red", "Blue", "Green", "Yellow"], durationMinutes: 1440 },
      });
      console.log(`Created poll: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Post with paid partnership">
    Use the `paid_partnership` field to indicate that this Post is a paid partnership (i.e., the author is disclosing it contains paid promotion). When set to `true`, the Post will be labeled as a paid promotion.

    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X POST "https://api.x.com/2/tweets" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN" \
        -H "Content-Type: application/json" \
        -d '{
          "text": "Excited to partner with Acme on their latest launch!",
          "paid_partnership": true
        }'
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Post with paid partnership
      response = client.posts.create(
          text="Excited to partner with Acme on their latest launch!",
          paid_partnership=True
      )
      print(f"Created paid partnership post: {response.data.id}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Post with paid partnership
      const response = await client.posts.create({
        text: "Excited to partner with Acme on their latest launch!",
        paidPartnership: true,
      });
      console.log(`Created paid partnership post: ${response.data?.id}`);
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

***

## Delete a Post

<Steps>
  <Step title="Get the Post ID">
    You need the ID of the Post you want to delete. This is returned when you create a Post.
  </Step>

  <Step title="Send a DELETE request">
    <CodeGroup dropdown>
      ```bash cURL theme={null}
      curl -X DELETE "https://api.x.com/2/tweets/1445880548472328192" \
        -H "Authorization: Bearer $USER_ACCESS_TOKEN"
      ```

      ```python Python SDK theme={null}
      from xdk import Client
      from xdk.oauth1_auth import OAuth1

      oauth1 = OAuth1(
          api_key="YOUR_API_KEY",
          api_secret="YOUR_API_SECRET",
          access_token="YOUR_ACCESS_TOKEN",
          access_token_secret="YOUR_ACCESS_TOKEN_SECRET"
      )

      client = Client(auth=oauth1)

      # Delete a Post
      response = client.posts.delete("1445880548472328192")
      print(f"Deleted: {response.data.deleted}")
      ```

      ```javascript JavaScript SDK theme={null}
      import { Client, OAuth1 } from "@xdevplatform/xdk";

      const oauth1 = new OAuth1({
        apiKey: "YOUR_API_KEY",
        apiSecret: "YOUR_API_SECRET",
        accessToken: "YOUR_ACCESS_TOKEN",
        accessTokenSecret: "YOUR_ACCESS_TOKEN_SECRET",
      });

      const client = new Client({ oauth1 });

      // Delete a Post
      const response = await client.posts.delete("1445880548472328192");
      console.log(`Deleted: ${response.data?.deleted}`);
      ```
    </CodeGroup>
  </Step>

  <Step title="Confirm deletion">
    ```json theme={null}
    {
      "data": {
        "deleted": true
      }
    }
    ```
  </Step>
</Steps>

<Warning>
  You can only delete Posts that you authored.
</Warning>

***

## Next steps

<CardGroup cols={2}>
  <Card title="Integration guide" icon="book" href="/x-api/posts/manage-tweets/integrate">
    Key concepts and best practices
  </Card>

  <Card title="Media upload" icon="image" href="/x-api/media/quickstart/media-upload-chunked">
    Upload media for Posts
  </Card>

  <Card title="API Reference" icon="code" href="/x-api/posts/create-post">
    Full endpoint documentation
  </Card>

  <Card title="Sample code" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    Working code examples
  </Card>
</CardGroup>
