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

# Quickstart

> Set up activity stream subscriptions and receive events

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 setting up activity stream subscriptions to receive real-time account activity events.

<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
  * Your App's Bearer Token
</Note>

***

<Steps>
  <Step title="Create a subscription" icon="bell">
    Subscribe to a user's activity events:

    <Tabs>
      <Tab title="cURL">
        ```bash theme={null}
        curl -X POST "https://api.x.com/2/activity/subscriptions" \
          -H "Authorization: Bearer $BEARER_TOKEN" \
          -H "Content-Type: application/json" \
          -d '{
            "user_id": "2244994945",
            "event_types": ["tweet_create_events", "favorite_events", "follow_events"]
          }'
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        import requests

        bearer_token = "YOUR_BEARER_TOKEN"

        url = "https://api.x.com/2/activity/subscriptions"
        headers = {
            "Authorization": f"Bearer {bearer_token}",
            "Content-Type": "application/json"
        }
        payload = {
            "user_id": "2244994945",
            "event_types": ["tweet_create_events", "favorite_events", "follow_events"]
        }

        response = requests.post(url, headers=headers, json=payload)
        print(response.json())
        ```
      </Tab>
    </Tabs>

    **Response:**

    ```json theme={null}
    {
      "data": {
        "id": "1234567890",
        "user_id": "2244994945",
        "event_types": ["tweet_create_events", "favorite_events", "follow_events"],
        "created_at": "2024-01-15T10:00:00.000Z"
      }
    }
    ```
  </Step>

  <Step title="Connect to the stream" icon="plug">
    Open a persistent connection to receive events:

    <Tabs>
      <Tab title="cURL">
        ```bash theme={null}
        curl "https://api.x.com/2/activity/stream" \
          -H "Authorization: Bearer $BEARER_TOKEN"
        ```
      </Tab>

      <Tab title="Python">
        ```python theme={null}
        import requests

        bearer_token = "YOUR_BEARER_TOKEN"

        url = "https://api.x.com/2/activity/stream"
        headers = {"Authorization": f"Bearer {bearer_token}"}

        response = requests.get(url, headers=headers, stream=True)

        for line in response.iter_lines():
            if line:
                print(line.decode("utf-8"))
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Process incoming events" icon="message">
    Events stream as JSON objects:

    ```json theme={null}
    {
      "for_user_id": "2244994945",
      "event_type": "tweet_create_events",
      "created_at": "2024-01-15T10:30:00.000Z",
      "tweet_create_events": [
        {
          "id": "1234567890",
          "text": "Hello from the stream!",
          "author_id": "2244994945"
        }
      ]
    }
    ```
  </Step>
</Steps>

***

## Available event types

| Event                   | Description                 |
| :---------------------- | :-------------------------- |
| `tweet_create_events`   | User posts a new Post       |
| `favorite_events`       | User likes a Post           |
| `follow_events`         | User follows or is followed |
| `direct_message_events` | User sends or receives a DM |
| `block_events`          | User blocks or unblocks     |
| `mute_events`           | User mutes or unmutes       |

***

## Manage subscriptions

<AccordionGroup>
  <Accordion title="List subscriptions">
    Get all active subscriptions:

    ```bash theme={null}
    curl "https://api.x.com/2/activity/subscriptions" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Accordion>

  <Accordion title="Update a subscription">
    Modify event types for a subscription:

    ```bash theme={null}
    curl -X PUT "https://api.x.com/2/activity/subscriptions/1234567890" \
      -H "Authorization: Bearer $BEARER_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "event_types": ["tweet_create_events", "favorite_events"]
      }'
    ```
  </Accordion>

  <Accordion title="Delete a subscription">
    Remove a subscription:

    ```bash theme={null}
    curl -X DELETE "https://api.x.com/2/activity/subscriptions/1234567890" \
      -H "Authorization: Bearer $BEARER_TOKEN"
    ```
  </Accordion>
</AccordionGroup>

***

## Next steps

<CardGroup cols={2}>
  <Card title="Account Activity API" icon="bell" href="/x-api/account-activity/introduction">
    Webhook-based alternative
  </Card>

  <Card title="API Reference" icon="code" href="/x-api/activity/activity-stream">
    Full endpoint documentation
  </Card>
</CardGroup>
