Introduction

The manage DM blocks endpoints enable you to block or unblock a specified account on behalf of an authenticated user. For these endpoints, there are two POST methods available:

  • /2/users/:id/dm/block: Allows you to block an account
  • /2/users/:id/dm/unblock: Allows you to unblock an account

Getting started

Authentication

Since you are making requests on behalf of a user, you must authenticate these endpoints with either OAuth 1.0a User Context or OAuth 2.0 Authorization Code with PKCE, and utilize the user Access Tokens associated with the user you are making the request on behalf of. You can generate this user Access Token using the 3-legged OAuth flow (OAuth 1.0a) or using the Authorization Code with PKCE grant flow (OAuth 2.0).

Making a request

Block

Once a user has authenticated with your app, you can call the Block endpoint on behalf of user as shown below:

curl --request POST 'https://api.twitter.com/2/users/:id/dm/block' --header 'Authorization: ••••••'

If the request is successful, you should see the JSON response as shown below:

{
   "data": {
       "blocked": true
   }
}

Unblock

Once a user has authenticated with your app, you can call the Unblock endpoint on behalf of user as shown below:

curl --request POST 'https://api.twitter.com/2/users/:id/dm/unblock' --header 'Authorization: ••••••'

If the request is successful, you should see the JSON response as shown below:

{
   "data": {
       "blocked": false
   }
}