Getting started with the manage Bookmarks endpoints
This quick start guide will help you make your first request to the manage Bookmarks endpoints using Postman.
If you would like to see sample code in different languages, please visit our X API v2 sample code GitHub repository.
Prerequisites
To complete this guide, you will need to have a set of keys and tokens to authenticate your request. You can generate these keys and tokens by following these steps:
- Sign up for a developer account and receive approval.
- Create a Project and an associated developer App in the developer portal.
- Navigate to your App's “Keys and tokens” page to generate the required credentials. Make sure to save all credentials in a secure location.
Steps to build a manage Bookmarks request
Step one: Start with a tool or library
There are several different tools, code examples, and libraries that you can use to make a request to this endpoint, but we are going to use the Postman tool here to simplify the process.
To load the X API v2 Postman collection into your environment, please click on the following button:
Once you have the X API v2 collection loaded in Postman, navigate to the “Bookmarks” folder, and select “Create a Bookmark”.
Step two: Authenticate your request
To make a successful request to this endpoint, you will need to use OAuth 2.0 Authorization Code Flow with PKCE. You can generate an access token within Postman.
If you go to the tab entitled “Authorization” and select “OAuth 2.0”.
In this tab, be sure to follow these steps:
Name your token
Select the Grant Type as Authorization Code (with PKCE)
Update the parameters:
Callback URL - https://www.example.com
This should be matching the callback URL you set in your auth settings page in the Developer Portal.
Auth URL - https://twitter.com/i/oauth2/authorize
Access Token URL - https://api.x.com/2/oauth2/token
Client ID - Cut and paste OAuth 2.0 client ID from the Developer Portal
Client Secret - Cut and paste OAuth 2.0 client ID from the Developer Portal. You will need this only if you are using an App type that is a confidential client.
Update the scopes with the following values: post.read users.read bookmark.write
Populate the field state with “State”
Click where it says “Generate Token”
Press the save icon to save the folder changes.
You may get a message that you are not logged into X. If you get this error, you will need to log in to the X account inside of Postman you are trying to post on behalf of.
Step three: Specify a user
With this endpoint, you must specify the user ID whose followers you would like to receive in the response. For example, the user ID for @XDevelopers is 2244994945
.
In Postman, navigate to the “Params” tab and enter the ID of yourself or an authenticated user as the value for the id parameter.
Key |
Value |
|
id |
|
Step four: Specify Specify a Post you want to Bookmark
You will want to navigate to the “Body” tab and make sure the Post ID is set to the one you are looking to save to your Bookmarks. The JSON payload should look similar to the one below.
{"tweet_id": "1460323737035677698"}
Step five: Make your request and review your response
Once you have everything set up, hit the "Send" button, and you will receive a similar response to the following example response:
{
"data": {
"bookmarked": true
}
}
To delete a Post, select the “Remove a Bookmark” request also found in the “Bookmarks” folder of the X API v2 collection loaded in Postman. You will first want to specify the user ID of the user you are making a request on behalf of as the value for the “id
” column. This endpoint also requires the ID of the Post you wish to delete. Then, in the “Params” tab, enter the ID of the Post you wish to delete as the value for the “tweet_id
” column.
When you have a successful delete request, you will receive a response similar to the following example:
{
"data": {
"bookmarked": false
}
}