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

# Integration Guide

> This guide covers the key concepts you need to integrate the blocks endpoints into your. Reference for the X API v2 standard tier covering blocks.

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>;
};

This guide covers the key concepts you need to integrate the blocks endpoints into your application.

<Callout icon="/icons/xds/icon-key.svg" color="#22C55E" iconType="regular">
  The block and unblock users endpoints are only available under the Enterprise plan. You can fill out the Enterprise interest form [here](/forms/enterprise-api-interest).
</Callout>

***

## Authentication

Blocks endpoints require user authentication:

| Method | Description |
| :- | :- |
| [OAuth 2.0 Authorization Code with PKCE](/resources/fundamentals/authentication#oauth-2-0-authorization-code-flow-with-pkce-2) | Recommended for new applications |
| [OAuth 1.0a User Context](/resources/fundamentals/authentication) | Legacy support |

<Warning>
  App-Only authentication is not supported. You must authenticate on behalf of a user.
</Warning>

### Required scopes (OAuth 2.0)

| Scope | Required for |
| :- | :- |
| `block.read` | Retrieving blocked accounts |
| `block.write` | Blocking and unblocking accounts |
| `users.read` | Required with block scopes |

***

## Endpoints overview

| Method | Endpoint | Description | Availability |
| :- | :- | :- | :- |
| GET | `/2/users/:id/blocking` | Get list of blocked accounts | <div className="flex items-center gap-1 flex-nowrap whitespace-nowrap"><Badge color="blue" size="xs">Pay-per-use</Badge><Badge color="green" size="xs">Enterprise</Badge></div> |
| POST | `/2/users/:id/blocking` | Block an account | <Badge color="green" size="xs">Enterprise</Badge> |
| DELETE | `/2/users/:source_user_id/blocking/:target_user_id` | Unblock an account | <Badge color="green" size="xs">Enterprise</Badge> |

***

## Fields and expansions

### Default response

```json theme={null}
{
  "data": [
    {
      "id": "1234567890",
      "name": "Example User",
      "username": "example"
    }
  ]
}
```

### Available fields

<Accordion title="user.fields">
  | Field | Description |
  | :- | :- |
  | `created_at` | Account creation date |
  | `description` | User bio |
  | `profile_image_url` | Avatar URL |
  | `public_metrics` | Follower/following counts |
  | `verified` | Verification status |
</Accordion>

<Accordion title="expansions">
  | Expansion | Description |
  | :- | :- |
  | `pinned_tweet_id` | User's pinned Post |
</Accordion>

***

## What happens when you block

<CardGroup cols={2}>
  <Card title="They can't" icon="xmark">
    * See your Posts (unless logged out)
    * Follow you
    * Send you DMs
    * Add you to Lists
    * Tag you in photos
  </Card>

  <Card title="You can't" icon="xmark">
    * See their Posts
    * Follow them
    * Send them DMs
  </Card>
</CardGroup>

<Note>
  When you block someone who follows you, they are automatically unfollowed.
</Note>

***

## Pagination

For users with large block lists, results are paginated:

<CodeGroup dropdown>
  ```bash cURL theme={null}
  # First request
  curl "https://api.x.com/2/users/123/blocking?max_results=100" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"

  # Subsequent request with pagination token
  curl "https://api.x.com/2/users/123/blocking?max_results=100&pagination_token=NEXT_TOKEN" \
    -H "Authorization: Bearer $USER_ACCESS_TOKEN"
  ```

  ```python title="Python SDK" lines wrap icon="python" theme={null}
  from xdk import Client

  # Use OAuth 2.0 user access token
  client = Client(bearer_token="YOUR_USER_ACCESS_TOKEN")

  # The SDK handles pagination automatically
  all_blocked = []

  for page in client.users.get_blocking(user_id="123", max_results=100):
      if page.data:
          all_blocked.extend(page.data)

  print(f"Blocked {len(all_blocked)} users")
  ```

  ```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ accessToken: "YOUR_USER_ACCESS_TOKEN" });

  async function getAllBlockedUsers(userId) {
    const allBlocked = [];

    // The SDK handles pagination automatically
    const paginator = client.users.getBlocking(userId, { maxResults: 100 });

    for await (const page of paginator) {
      if (page.data) {
        allBlocked.push(...page.data);
      }
    }

    return allBlocked;
  }

  // Usage
  const blocked = await getAllBlockedUsers("123");
  console.log(`Blocked ${blocked.length} users`);
  ```
</CodeGroup>

***

## Error handling

| Status | Error | Solution |
| :- | :- | :- |
| 400 | Invalid request | Check user ID format |
| 401 | Unauthorized | Verify access token |
| 403 | Forbidden | Check scopes and permissions. Block/unblock require [Enterprise](/forms/enterprise-api-interest) |
| 404 | Not Found | User doesn't exist |
| 429 | Too Many Requests | Wait and retry |

***

## Next steps

<CardGroup cols={2}>
  <Card title="Quickstart" icon="https://mintcdn.com/x-preview-mintlify-508d47e7/ZoQkjcRw6TIbGlxg/icons/xds/icon-rocket.svg?fit=max&auto=format&n=ZoQkjcRw6TIbGlxg&q=85&s=daeea53680cb63e65f5afdaa0a61ff99" href="/x-api/users/blocks/quickstart" width="24" height="24" data-path="icons/xds/icon-rocket.svg">
    Make your first blocks request
  </Card>

  <Card title="Mutes" icon="volume-xmark" href="/x-api/users/mutes/introduction">
    Mute users instead of blocking
  </Card>

  <Card title="API Reference" icon="https://mintcdn.com/x-preview-mintlify-508d47e7/yrNbfyssZy5Znz8E/icons/xds/icon-code.svg?fit=max&auto=format&n=yrNbfyssZy5Znz8E&q=85&s=22045e00591dc6e3e540a973ccd4f74b" href="/x-api/users/get-blocking" width="24" height="24" data-path="icons/xds/icon-code.svg">
    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>
