Chilkat Online Tools

SQL Server / Atlassian Confluence Cloud / Get user accountIds

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, 'key', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'key', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'username', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'username', '<string>'
    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/user/bulk/migration', @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)

    -- {
    --   "results": [
    --     {
    --       "username": "minim quis Ut ut",
    --       "key": "nisi dolore eu",
    --       "accountId": "ut esse"
    --     },
    --     {
    --       "username": "consectetur reprehend",
    --       "key": "irure eu in",
    --       "accountId": "aliqua occaecat"
    --     }
    --   ],
    --   "start": 64265328,
    --   "limit": 95109652,
    --   "size": -92940668,
    --   "_links": {}
    -- }

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

    DECLARE @username nvarchar(4000)

    DECLARE @key nvarchar(4000)

    DECLARE @accountId nvarchar(4000)

    DECLARE @start int
    EXEC sp_OAMethod @jResp, 'IntOf', @start OUT, 'start'
    DECLARE @limit int
    EXEC sp_OAMethod @jResp, 'IntOf', @limit OUT, 'limit'
    DECLARE @size int
    EXEC sp_OAMethod @jResp, 'IntOf', @size OUT, 'size'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'results'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @username OUT, 'results[i].username'
        EXEC sp_OAMethod @jResp, 'StringOf', @key OUT, 'results[i].key'
        EXEC sp_OAMethod @jResp, 'StringOf', @accountId OUT, 'results[i].accountId'
        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 "key=%3Cstring%3E"
	-d "key=%3Cstring%3E"
	-d "username=%3Cstring%3E"
	-d "username=%3Cstring%3E"
	-d "start=0"
	-d "limit=200"
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/user/bulk/migration

Postman Collection Item JSON

{
  "name": "Get user accountIds",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/user/bulk/migration?key=<string>&key=<string>&username=<string>&username=<string>&start=0&limit=200",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "user",
        "bulk",
        "migration"
      ],
      "query": [
        {
          "key": "key",
          "value": "<string>",
          "description": "(Required) The key of a user. To specify multiple users, pass multiple key parameters separated by ampersands.\nFor example, key=mia&key=alana. Required if username isn't provided. Cannot be provided if username is present."
        },
        {
          "key": "key",
          "value": "<string>",
          "description": "(Required) The key of a user. To specify multiple users, pass multiple key parameters separated by ampersands.\nFor example, key=mia&key=alana. Required if username isn't provided. Cannot be provided if username is present."
        },
        {
          "key": "username",
          "value": "<string>",
          "description": "The username of a user. To specify multiple users, pass multiple username parameters separated by ampersands.\nFor example, username=mia&username=alana. Required if key isn't provided. Cannot be provided if key is present."
        },
        {
          "key": "username",
          "value": "<string>",
          "description": "The username of a user. To specify multiple users, pass multiple username parameters separated by ampersands.\nFor example, username=mia&username=alana. Required if key isn't provided. Cannot be provided if key is present."
        },
        {
          "key": "start",
          "value": "0",
          "description": "The index of the first item to return in a page of results (page offset)."
        },
        {
          "key": "limit",
          "value": "200",
          "description": "The maximum number of results to return per page.\nNote, this may be restricted by fixed system limits."
        }
      ]
    },
    "description": "Returns the accountIds for the users specified in the key or username parameters. Note that multiple key and username parameters can be specified.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Confluence Administrator' global permission if specifying a user, otherwise\npermission to access the Confluence site ('Can use' global permission)."
  },
  "response": [
    {
      "name": "Returned if the request is successful.",
      "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/user/bulk/migration?key=<string>&key=<string>&username=<string>&username=<string>&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "user",
            "bulk",
            "migration"
          ],
          "query": [
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "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 \"results\": [\n  {\n   \"username\": \"minim quis Ut ut\",\n   \"key\": \"nisi dolore eu\",\n   \"accountId\": \"ut esse\"\n  },\n  {\n   \"username\": \"consectetur reprehend\",\n   \"key\": \"irure eu in\",\n   \"accountId\": \"aliqua occaecat\"\n  }\n ],\n \"start\": 64265328,\n \"limit\": 95109652,\n \"size\": -92940668,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if no `username` or 'key' is specified.",
      "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/user/bulk/migration?key=<string>&key=<string>&username=<string>&username=<string>&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "user",
            "bulk",
            "migration"
          ],
          "query": [
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "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;\n\n- The calling user does not have permission to view users.\n- A schema has not been defined for this response code.",
      "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/user/bulk/migration?key=<string>&key=<string>&username=<string>&username=<string>&start=0&limit=200",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "user",
            "bulk",
            "migration"
          ],
          "query": [
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "key",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "key": "username",
              "value": "<string>"
            },
            {
              "key": "start",
              "value": "0"
            },
            {
              "key": "limit",
              "value": "200"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}