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

# Quickstart de manage Posts de X API v2

> Quickstart paso a paso para crear y eliminar Posts con el nivel estándar de X API v2, incluyendo autenticación, payloads de solicitud y ejemplos.

export const Button = ({href, children}) => {
  return <div className="not-prose">
    <a href={href}>
      <button className="x-btn">
        <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>;
};

Esta guía te muestra cómo crear y eliminar Posts usando la X API.

<Note>
  **Requisitos previos**

  Antes de comenzar, necesitarás:

  * Una [cuenta de desarrollador](https://developer.x.com/en/portal/petition/essential/basic-info) con una App aprobada
  * User Access Tokens (OAuth 1.0a o OAuth 2.0 PKCE)
</Note>

***

## Crear un Post

<Steps>
  <Step title="Prepara tu solicitud">
    El endpoint POST `/2/tweets` requiere un cuerpo JSON con al menos `text` o `media`:

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

  <Step title="Envía la solicitud">
    <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 title="Python SDK" lines wrap icon="python" 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)

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

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

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

  <Step title="Revisa la respuesta">
    Una respuesta exitosa incluye el `id` y `text` del nuevo Post:

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

***

## Ejemplos avanzados

<AccordionGroup>
  <Accordion title="Responder a un 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 title="Python SDK" lines wrap icon="python" 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)

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

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

      // Crea una respuesta
      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="Citar un 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 title="Python SDK" lines wrap icon="python" 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)

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

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

      // Cita un 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 con media">
    Primero, sube el media usando el [endpoint de Media Upload](/x-api/media/quickstart/media-upload-chunked), luego haz referencia al `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 title="Python SDK" lines wrap icon="python" 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 con media
      response = client.posts.create(
          text="Photo of the day!",
          media={"media_ids": ["1234567890123456789"]}
      )
      print(f"Created Post with media: {response.data.id}")
      ```

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 con 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 con encuesta">
    <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 title="Python SDK" lines wrap icon="python" 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 con encuesta
      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 title="JavaScript SDK" lines wrap icon="square-js" 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 con encuesta
      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 con paid partnership">
    Utiliza el campo `paid_partnership` para indicar que este Post es una asociación pagada (es decir, el autor está declarando que contiene una promoción pagada). Cuando se establece en `true`, el Post será etiquetado como una promoción pagada.

    <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 title="Python SDK" lines wrap icon="python" 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 con 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 title="JavaScript SDK" lines wrap icon="square-js" 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 con 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>

***

## Eliminar un Post

<Steps>
  <Step title="Obtén el ID del Post">
    Necesitas el ID del Post que quieres eliminar. Este se devuelve cuando creas un Post.
  </Step>

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

      ```python title="Python SDK" lines wrap icon="python" 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)

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

      ```javascript title="JavaScript SDK" lines wrap icon="square-js" 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 });

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

  <Step title="Confirma la eliminación">
    ```json theme={null}
    {
      "data": {
        "deleted": true
      }
    }
    ```
  </Step>
</Steps>

<Warning>
  Solo puedes eliminar Posts que hayas creado tú.
</Warning>

***

## Próximos pasos

<CardGroup cols={2}>
  <Card title="Guía de integración" icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-book.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=22ac564792481d14ae36a941546039c8" href="/x-api/posts/manage-tweets/integrate" width="24" height="24" data-path="icons/xds/icon-book.svg">
    Conceptos clave y mejores prácticas
  </Card>

  <Card title="Subida de media" icon="https://mintcdn.com/x-preview/oR-aRNyj1BKPJtxM/icons/xds/icon-photo.svg?fit=max&auto=format&n=oR-aRNyj1BKPJtxM&q=85&s=d0986097dcff55478c32801b20440ecc" href="/x-api/media/quickstart/media-upload-chunked" width="24" height="24" data-path="icons/xds/icon-photo.svg">
    Sube media para Posts
  </Card>

  <Card title="Referencia de la API" icon="https://mintcdn.com/x-preview/ygI6sSJPehlc0qNT/icons/xds/icon-code.svg?fit=max&auto=format&n=ygI6sSJPehlc0qNT&q=85&s=488e23401b19225b89acc0136d242219" href="/x-api/posts/create-post" width="24" height="24" data-path="icons/xds/icon-code.svg">
    Documentación completa del endpoint
  </Card>

  <Card title="Código de ejemplo" icon="github" href="https://github.com/xdevplatform/Twitter-API-v2-sample-code">
    Ejemplos de código funcional
  </Card>
</CardGroup>
