---
description: View and update domain blocks.
---

# domain\_blocks

## Fetch domain blocks

<mark style="color:blue;">`GET`</mark> `https://mastodon.example/api/v1/domain_blocks`

View domains the user has blocked.\
\
**Returns:** Array of strings\
**OAuth:** User token + `read:blocks` or `follow`\
**Version:**\
1.4.0 - added

#### Query Parameters

| Name      | Type   | Description                                                                                                                    |
| --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------ |
| max\_id   | string | **Internal parameter.** Use HTTP Link header from response for pagination.                                                     |
| since\_id | string | **Internal parameter.** Use HTTP Link header from response for pagination.                                                     |
| limit     | string | Maximum number of results to return per page. Defaults to 40. NOTE: Pagination is done with the Link header from the response. |

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Bearer \<user token> |

{% tabs %}
{% tab title="200 Sample call with limit=2. Because domain ids are not public, you must parse the HTTP Link header to access next and previous pages." %}
```javascript
Link: <https://mastodon.social/api/v1/domain_blocks?limit=2&max_id=16194>; rel="next", <https://mastodon.social/api/v1/domain_blocks?limit=2&since_id=16337>; rel="prev"

["nsfw.social","artalley.social"]
```
{% endtab %}

{% tab title="401 Incorrect Authorization header" %}
```javascript
{
  "error": "The access token is invalid"
}
```
{% endtab %}
{% endtabs %}

## Block a domain

<mark style="color:green;">`POST`</mark> `https://mastodon.example/api/v1/domain_blocks`

Block a domain to:\
\- hide all public posts from it\
\- hide all notifications from it\
\- remove all followers from it\
\- prevent following new users from it (but does not remove existing follows)\
\
**Returns:** n/a\
**OAuth:** User token + `write:blocks` or `follow`\
**Version:** \
1.4.0 - added

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Bearer \<user token> |

#### Request Body

| Name   | Type   | Description      |
| ------ | ------ | ---------------- |
| domain | string | Domain to block. |

{% tabs %}
{% tab title="200 If the call was successful, an empty object will be returned. Note that the call will be successful even if the domain is already blocked or if the domain does not exist or if the domain is not a domain." %}
```javascript
{}
```
{% endtab %}

{% tab title="401 Incorrect Authorization header" %}
```javascript
{
  "error": "The access token is invalid"
}
```
{% endtab %}

{% tab title="422 If domain is not provided or contains spaces, the request will fail." %}
{% tabs %}
{% tab title="empty" %}
```javascript
{
  "error": "Validation failed: Domain can't be blank"
}
```
{% endtab %}

{% tab title="invalid" %}
```javascript
{
  "error": "Validation failed: Domain is not a valid domain name"
}
```
{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}

## Unblock a domain

<mark style="color:red;">`DELETE`</mark> `https://mastodon.example/api/v1/domain_blocks`

Remove a domain block, if it exists in the user's array of blocked domains.\
\
**Returns:** n/a\
**OAuth:** User token + `write:blocks` or `follow`\
**Version history:**\
1.4.0 - added

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | Bearer \<user token> |

#### Request Body

| Name   | Type   | Description        |
| ------ | ------ | ------------------ |
| domain | string | Domain to unblock. |

{% tabs %}
{% tab title="200 If the call was successful, an empty object will be returned. Note that the call will be successful even if the domain was not previously blocked." %}
```javascript
{}
```
{% endtab %}

{% tab title="401 Incorrect Authorization header" %}
```javascript
{
  "error": "The access token is invalid"
}
```
{% endtab %}

{% tab title="422 If domain is not provided or contains spaces, the request will fail." %}
{% tabs %}
{% tab title="empty" %}
```javascript
{
  "error": "Validation failed: Domain can't be blank"
}
```
{% endtab %}

{% tab title="invalid domain" %}
```javascript
{
  "error": "Validation failed: Domain is not a valid domain name"
}
```
{% endtab %}
{% endtabs %}
{% endtab %}
{% endtabs %}
