Chilkat Online Tools

delphiDll / Atlassian Confluence Cloud / Get labels for content

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
queryParams: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
prefix: PWideChar;
name: PWideChar;
id: PWideChar;
label: PWideChar;
start: Integer;
limit: Integer;
size: Integer;
i: Integer;
count_i: Integer;

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

http := CkHttp_Create();

queryParams := CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,'prefix','<string>');
CkJsonObject_UpdateInt(queryParams,'start',0);
CkJsonObject_UpdateInt(queryParams,'limit',200);

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

resp := CkHttp_QuickRequestParams(http,'GET','https://your-domain.atlassian.net/wiki/rest/api/content/:id/label',queryParams);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "results": [
//     {
//       "prefix": "Duis elit dolor officia",
//       "name": "non sunt",
//       "id": "nulla veniam",
//       "label": "deserunt Ut Excepteur magna"
//     },
//     {
//       "prefix": "in consequat deserun",
//       "name": "officia cillum enim",
//       "id": "Lorem quis esse amet",
//       "label": "dolore esse"
//     }
//   ],
//   "start": -32316568,
//   "limit": -3993073,
//   "size": -78086889,
//   "_links": {}
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

start := CkJsonObject_IntOf(jResp,'start');
limit := CkJsonObject_IntOf(jResp,'limit');
size := CkJsonObject_IntOf(jResp,'size');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'results');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    prefix := CkJsonObject__stringOf(jResp,'results[i].prefix');
    name := CkJsonObject__stringOf(jResp,'results[i].name');
    id := CkJsonObject__stringOf(jResp,'results[i].id');
    label := CkJsonObject__stringOf(jResp,'results[i].label');
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -G -d "prefix=%3Cstring%3E"
	-d "start=0"
	-d "limit=200"
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/content/:id/label

Postman Collection Item JSON

{
  "name": "Get labels for content",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/label?prefix=<string>&start=0&limit=200",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "label"
      ],
      "query": [
        {
          "key": "prefix",
          "value": "<string>",
          "description": "Filters the results to labels with the specified prefix. If this parameter\nis not specified, then labels with any prefix will be returned.\n\n- `global` prefix is used by default when a user adds a label\nvia the UI.\n- `my` prefix can be explicitly added by a user when adding a label\nvia the UI, e.g. 'my:example-label'. Also, when a page is selected as\na favourite, the 'my:favourite' label is automatically added.\n- `team` can used when adding labels via [Add labels to content](#api-content-id-label-post)\nbut is not used in the UI."
        },
        {
          "key": "start",
          "value": "0",
          "description": "The starting index of the returned labels."
        },
        {
          "key": "limit",
          "value": "200",
          "description": "The maximum number of labels to return per page. Note,\nthis may be restricted by fixed system limits."
        }
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the content to be queried for its labels."
        }
      ]
    },
    "description": "Returns the labels on a piece of content.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'View' permission for the space and permission to view the content if it is a page."
  },
  "response": [
    {
      "name": "Returned if the requested labels are returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/label?prefix=<string>&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "label"
          ],
          "query": [
            {
              "key": "prefix",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"results\": [\n  {\n   \"prefix\": \"Duis elit dolor officia\",\n   \"name\": \"non sunt\",\n   \"id\": \"nulla veniam\",\n   \"label\": \"deserunt Ut Excepteur magna\"\n  },\n  {\n   \"prefix\": \"in consequat deserun\",\n   \"name\": \"officia cillum enim\",\n   \"id\": \"Lorem quis esse amet\",\n   \"label\": \"dolore esse\"\n  }\n ],\n \"start\": -32316568,\n \"limit\": -3993073,\n \"size\": -78086889,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if;\n\n- There is no content with the given ID.\n- The calling user does not have permission to view the content.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/label?prefix=<string>&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "label"
          ],
          "query": [
            {
              "key": "prefix",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ],
          "variable": [
            {
              "key": "id"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}