Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')
* Use this online tool to generate code from sample JSON: Generate Code to Create JSON
* The following JSON is sent in the request body.
* {
* "tweet_id": "1503863301276827651"
* }
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("tweet_id","1503863301276827651")
* Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loResp = loHttp.PostJson3("https://api.twitter.com/2/users/:id/bookmarks","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
CANCEL
ENDIF
? STR(loResp.StatusCode)
? loResp.BodyStr
RELEASE loResp
RELEASE loHttp
RELEASE loJson
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-d '{
"tweet_id": "1503863301276827651"
}'
https://api.twitter.com/2/users/:id/bookmarks
Postman Collection Item JSON
{
"name": "Bookmark a Tweet",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"// This script extracts the ID of the authenticating user, so you do not have to pass it yourself.",
"if (!pm.environment.get('access_token') || !pm.request.url.path.includes(':id')) {",
" return;",
"}",
"",
"const [userId] = pm.environment.get('access_token').split('-');",
"",
"if (!userId) {",
" return;",
"}",
"",
"const userIdIndex = pm.request.url.path.indexOf(':id');",
"pm.request.url.path[userIdIndex] = userId;"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "state",
"value": "",
"type": "string"
},
{
"key": "scope",
"value": "",
"type": "string"
},
{
"key": "accessTokenUrl",
"value": "",
"type": "string"
},
{
"key": "authUrl",
"value": "",
"type": "string"
},
{
"key": "tokenName",
"value": "bookmarks",
"type": "string"
},
{
"key": "redirect_uri",
"value": "",
"type": "string"
},
{
"key": "clientId",
"value": "",
"type": "string"
},
{
"key": "grant_type",
"value": "authorization_code_with_pkce",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
}
]
},
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"tweet_id\": \"1503863301276827651\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.twitter.com/2/users/:id/bookmarks",
"protocol": "https",
"host": [
"api",
"twitter",
"com"
],
"path": [
"2",
"users",
":id",
"bookmarks"
],
"variable": [
{
"key": "id",
"value": "",
"description": "The ID of the user who wishes to like a Tweet. The ID must belong to the authenticating user.\n"
}
]
},
"description": "Allows an authenticated user to like a Tweet.\n\nFor full details, see the [API reference](https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-user_id-bookmarks) for this endpoint.\n\n[Sign up](https://t.co/signup) for the Twitter API"
},
"response": [
]
}