Chilkat Online Tools

unicodeCpp / Atlassian Confluence Cloud / Get Label information.

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;
    bool success;

    CkJsonObjectW queryParams;
    queryParams.UpdateString(L"name",L"");
    queryParams.UpdateString(L"type",L"");
    queryParams.UpdateInt(L"start",0);
    queryParams.UpdateInt(L"limit",200);

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken(L"<access_token>");

    CkHttpResponseW *resp = http.QuickRequestParams(L"GET",L"https://your-domain.atlassian.net/wiki/rest/api/label",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp->get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp->header());
        wprintf(L"Failed.\n");
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "label": {
    //     "prefix": "est dolore",
    //     "name": "elit magna culpa voluptate minim",
    //     "id": "fugiat in occaecat",
    //     "label": "Excepteur eu culpa qui non"
    //   },
    //   "associatedContents": {
    //     "results": [
    //       {
    //         "contentType": "attachment",
    //         "contentId": -15123374,
    //         "title": "est"
    //       },
    //       {
    //         "contentType": "attachment",
    //         "contentId": 29751066,
    //         "title": "in fugiat"
    //       }
    //     ],
    //     "size": -57367807,
    //     "start": 711472,
    //     "limit": -23936898
    //   }
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    const wchar_t *contentType = 0;
    int contentId;
    const wchar_t *title = 0;

    const wchar_t *Prefix = jResp.stringOf(L"label.prefix");
    const wchar_t *Name = jResp.stringOf(L"label.name");
    const wchar_t *Id = jResp.stringOf(L"label.id");
    const wchar_t *Label = jResp.stringOf(L"label.label");
    int Size = jResp.IntOf(L"associatedContents.size");
    int Start = jResp.IntOf(L"associatedContents.start");
    int Limit = jResp.IntOf(L"associatedContents.limit");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"associatedContents.results");
    while (i < count_i) {
        jResp.put_I(i);
        contentType = jResp.stringOf(L"associatedContents.results[i].contentType");
        contentId = jResp.IntOf(L"associatedContents.results[i].contentId");
        title = jResp.stringOf(L"associatedContents.results[i].title");
        i = i + 1;
    }
    }

Curl Command

curl -G -d "name="
	-d "type="
	-d "start=0"
	-d "limit=200"
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/label

Postman Collection Item JSON

{
  "name": "Get Label information.",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/label?name=&type=&start=0&limit=200",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "label"
      ],
      "query": [
        {
          "key": "name",
          "value": "",
          "description": "(Required) Name of the label to query."
        },
        {
          "key": "type",
          "value": "",
          "description": "The type of contents that are to be returned."
        },
        {
          "key": "start",
          "value": "0",
          "description": "The starting offset for the results."
        },
        {
          "key": "limit",
          "value": "200",
          "description": "The number of results to be returned."
        }
      ]
    },
    "description": "Returns label information and a list of contents associated with the label.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to access the Confluence site ('Can use' global permission). Only contents\nthat the user is permitted to view is returned."
  },
  "response": [
    {
      "name": "Returned if the query fetches zero or more results.",
      "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/label?name=&type=&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "label"
          ],
          "query": [
            {
              "key": "name",
              "value": ""
            },
            {
              "key": "type",
              "value": ""
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"label\": {\n  \"prefix\": \"est dolore\",\n  \"name\": \"elit magna culpa voluptate minim\",\n  \"id\": \"fugiat in occaecat\",\n  \"label\": \"Excepteur eu culpa qui non\"\n },\n \"associatedContents\": {\n  \"results\": [\n   {\n    \"contentType\": \"attachment\",\n    \"contentId\": -15123374,\n    \"title\": \"est\"\n   },\n   {\n    \"contentType\": \"attachment\",\n    \"contentId\": 29751066,\n    \"title\": \"in fugiat\"\n   }\n  ],\n  \"size\": -57367807,\n  \"start\": 711472,\n  \"limit\": -23936898\n }\n}"
    },
    {
      "name": "Returned if no label name is provide or\nif content type provided in the query is invalid.",
      "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/label?name=&type=&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "label"
          ],
          "query": [
            {
              "key": "name",
              "value": ""
            },
            {
              "key": "type",
              "value": ""
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the calling user does not have permission to view\nany content including label info.",
      "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/label?name=&type=&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "label"
          ],
          "query": [
            {
              "key": "name",
              "value": ""
            },
            {
              "key": "type",
              "value": ""
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the lable name is invalid or if no label is found for a given label.",
      "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/label?name=&type=&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "label"
          ],
          "query": [
            {
              "key": "name",
              "value": ""
            },
            {
              "key": "type",
              "value": ""
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}