Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Get Label information.

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'name', ''
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'type', ''
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'start', 0
    EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 200

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://your-domain.atlassian.net/wiki/rest/api/label', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @resp

        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END
    EXEC @hr = sp_OADestroy @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

    DECLARE @contentType nvarchar(4000)

    DECLARE @contentId int

    DECLARE @title nvarchar(4000)

    DECLARE @Prefix nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Prefix OUT, 'label.prefix'
    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'label.name'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'label.id'
    DECLARE @Label nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Label OUT, 'label.label'
    DECLARE @Size int
    EXEC sp_OAMethod @jResp, 'IntOf', @Size OUT, 'associatedContents.size'
    DECLARE @Start int
    EXEC sp_OAMethod @jResp, 'IntOf', @Start OUT, 'associatedContents.start'
    DECLARE @Limit int
    EXEC sp_OAMethod @jResp, 'IntOf', @Limit OUT, 'associatedContents.limit'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'associatedContents.results'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @contentType OUT, 'associatedContents.results[i].contentType'
        EXEC sp_OAMethod @jResp, 'IntOf', @contentId OUT, 'associatedContents.results[i].contentId'
        EXEC sp_OAMethod @jResp, 'StringOf', @title OUT, 'associatedContents.results[i].title'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

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": ""
    }
  ]
}