Chilkat Online Tools

delphiDll / Twitter API v2 / Update a list

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := CkHttp_Create();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "name": "update-name",
//   "description": "update-description",
//   "private": false
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'name','update-name');
CkJsonObject_UpdateString(json,'description','update-description');
CkJsonObject_UpdateBool(json,'private',False);

// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);

resp := CkHttp_PTextSb(http,'PUT','https://api.twitter.com/2/lists/:id',sbRequestBody,'utf-8','application/json',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "name": "update-name",
    "description": "update-description",
    "private": false
}'
https://api.twitter.com/2/lists/:id

Postman Collection Item JSON

{
  "name": "Update a list",
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"update-name\",\n    \"description\": \"update-description\",\n    \"private\": false\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.twitter.com/2/lists/:id",
      "protocol": "https",
      "host": [
        "api",
        "twitter",
        "com"
      ],
      "path": [
        "2",
        "lists",
        ":id"
      ],
      "variable": [
        {
          "key": "id",
          "value": null,
          "description": "The ID of the List you wish to update the metadata of - the List must be owned by the authenticated user"
        }
      ]
    },
    "description": "Allows the authenticated user to update a List they own.\n\nFor full details, see the [API reference](https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id) for this endpoint.\n\n[Sign up](https://t.co/signup) for the Twitter API"
  },
  "response": [
  ]
}