Chilkat Online Tools

SQL Server / Support API / Incremental User Export, Cursor Based

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
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'login'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    DECLARE @queryParams int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'start_time', '<integer>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'cursor', '<string>'
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'per_page', '<integer>'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://example.zendesk.com/api/v2/incremental/users/cursor', @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
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

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

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.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)

    -- {
    --   "after_cursor": "<string>",
    --   "after_url": "<string>",
    --   "before_cursor": "<string>",
    --   "before_url": "<string>",
    --   "end_of_stream": "<boolean>",
    --   "users": [
    --     {
    --       "name": "<string>",
    --       "active": "<boolean>",
    --       "alias": "<string>",
    --       "chat_only": "<boolean>",
    --       "created_at": "<string>",
    --       "custom_role_id": "<integer>",
    --       "default_group_id": "<integer>",
    --       "details": "<string>",
    --       "email": "<string>",
    --       "external_id": "<string>",
    --       "iana_time_zone": "<string>",
    --       "id": "<integer>",
    --       "last_login_at": "<string>",
    --       "locale": "<string>",
    --       "locale_id": "<integer>",
    --       "moderator": "<boolean>",
    --       "notes": "<string>",
    --       "only_private_comments": "<boolean>",
    --       "organization_id": "<integer>",
    --       "phone": "<string>",
    --       "photo": {
    --         "proidentbc0": -29354278.707036167,
    --         "fugiat_e_b": -98816029.91228342
    --       },
    --       "remote_photo_url": "<string>",
    --       "report_csv": "<boolean>",
    --       "restricted_agent": "<boolean>",
    --       "role": "<string>",
    --       "role_type": "<integer>",
    --       "shared": "<boolean>",
    --       "shared_agent": "<boolean>",
    --       "shared_phone_number": "<boolean>",
    --       "signature": "<string>",
    --       "suspended": "<boolean>",
    --       "tags": "<array>",
    --       "ticket_restriction": "<string>",
    --       "time_zone": "<string>",
    --       "two_factor_auth_enabled": "<boolean>",
    --       "updated_at": "<string>",
    --       "url": "<string>",
    --       "user_fields": {
    --         "culpa14b": true
    --       },
    --       "verified": "<boolean>"
    --     },
    --     {
    --       "name": "<string>",
    --       "active": "<boolean>",
    --       "alias": "<string>",
    --       "chat_only": "<boolean>",
    --       "created_at": "<string>",
    --       "custom_role_id": "<integer>",
    --       "default_group_id": "<integer>",
    --       "details": "<string>",
    --       "email": "<string>",
    --       "external_id": "<string>",
    --       "iana_time_zone": "<string>",
    --       "id": "<integer>",
    --       "last_login_at": "<string>",
    --       "locale": "<string>",
    --       "locale_id": "<integer>",
    --       "moderator": "<boolean>",
    --       "notes": "<string>",
    --       "only_private_comments": "<boolean>",
    --       "organization_id": "<integer>",
    --       "phone": "<string>",
    --       "photo": {
    --         "in223": -78887847,
    --         "quis20_": 61629027.23513341
    --       },
    --       "remote_photo_url": "<string>",
    --       "report_csv": "<boolean>",
    --       "restricted_agent": "<boolean>",
    --       "role": "<string>",
    --       "role_type": "<integer>",
    --       "shared": "<boolean>",
    --       "shared_agent": "<boolean>",
    --       "shared_phone_number": "<boolean>",
    --       "signature": "<string>",
    --       "suspended": "<boolean>",
    --       "tags": "<array>",
    --       "ticket_restriction": "<string>",
    --       "time_zone": "<string>",
    --       "two_factor_auth_enabled": "<boolean>",
    --       "updated_at": "<string>",
    --       "url": "<string>",
    --       "user_fields": {
    --         "aliquipe8": false
    --       },
    --       "verified": "<boolean>"
    --     }
    --   ]
    -- }

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

    DECLARE @name nvarchar(4000)

    DECLARE @active nvarchar(4000)

    DECLARE @alias nvarchar(4000)

    DECLARE @chat_only nvarchar(4000)

    DECLARE @created_at nvarchar(4000)

    DECLARE @custom_role_id nvarchar(4000)

    DECLARE @default_group_id nvarchar(4000)

    DECLARE @details nvarchar(4000)

    DECLARE @email nvarchar(4000)

    DECLARE @external_id nvarchar(4000)

    DECLARE @iana_time_zone nvarchar(4000)

    DECLARE @id nvarchar(4000)

    DECLARE @last_login_at nvarchar(4000)

    DECLARE @locale nvarchar(4000)

    DECLARE @locale_id nvarchar(4000)

    DECLARE @moderator nvarchar(4000)

    DECLARE @notes nvarchar(4000)

    DECLARE @only_private_comments nvarchar(4000)

    DECLARE @organization_id nvarchar(4000)

    DECLARE @phone nvarchar(4000)

    DECLARE @Proidentbc0 nvarchar(4000)

    DECLARE @Fugiat_e_b nvarchar(4000)

    DECLARE @remote_photo_url nvarchar(4000)

    DECLARE @report_csv nvarchar(4000)

    DECLARE @restricted_agent nvarchar(4000)

    DECLARE @role nvarchar(4000)

    DECLARE @role_type nvarchar(4000)

    DECLARE @v_shared nvarchar(4000)

    DECLARE @shared_agent nvarchar(4000)

    DECLARE @shared_phone_number nvarchar(4000)

    DECLARE @signature nvarchar(4000)

    DECLARE @suspended nvarchar(4000)

    DECLARE @tags nvarchar(4000)

    DECLARE @ticket_restriction nvarchar(4000)

    DECLARE @time_zone nvarchar(4000)

    DECLARE @two_factor_auth_enabled nvarchar(4000)

    DECLARE @updated_at nvarchar(4000)

    DECLARE @url nvarchar(4000)

    DECLARE @Culpa14b int

    DECLARE @verified nvarchar(4000)

    DECLARE @In223 int

    DECLARE @Quis20_ nvarchar(4000)

    DECLARE @Aliquipe8 int

    DECLARE @after_cursor nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @after_cursor OUT, 'after_cursor'
    DECLARE @after_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @after_url OUT, 'after_url'
    DECLARE @before_cursor nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @before_cursor OUT, 'before_cursor'
    DECLARE @before_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @before_url OUT, 'before_url'
    DECLARE @end_of_stream nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @end_of_stream OUT, 'end_of_stream'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'users'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'users[i].name'
        EXEC sp_OAMethod @jResp, 'StringOf', @active OUT, 'users[i].active'
        EXEC sp_OAMethod @jResp, 'StringOf', @alias OUT, 'users[i].alias'
        EXEC sp_OAMethod @jResp, 'StringOf', @chat_only OUT, 'users[i].chat_only'
        EXEC sp_OAMethod @jResp, 'StringOf', @created_at OUT, 'users[i].created_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @custom_role_id OUT, 'users[i].custom_role_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @default_group_id OUT, 'users[i].default_group_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @details OUT, 'users[i].details'
        EXEC sp_OAMethod @jResp, 'StringOf', @email OUT, 'users[i].email'
        EXEC sp_OAMethod @jResp, 'StringOf', @external_id OUT, 'users[i].external_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @iana_time_zone OUT, 'users[i].iana_time_zone'
        EXEC sp_OAMethod @jResp, 'StringOf', @id OUT, 'users[i].id'
        EXEC sp_OAMethod @jResp, 'StringOf', @last_login_at OUT, 'users[i].last_login_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @locale OUT, 'users[i].locale'
        EXEC sp_OAMethod @jResp, 'StringOf', @locale_id OUT, 'users[i].locale_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @moderator OUT, 'users[i].moderator'
        EXEC sp_OAMethod @jResp, 'StringOf', @notes OUT, 'users[i].notes'
        EXEC sp_OAMethod @jResp, 'StringOf', @only_private_comments OUT, 'users[i].only_private_comments'
        EXEC sp_OAMethod @jResp, 'StringOf', @organization_id OUT, 'users[i].organization_id'
        EXEC sp_OAMethod @jResp, 'StringOf', @phone OUT, 'users[i].phone'
        EXEC sp_OAMethod @jResp, 'StringOf', @Proidentbc0 OUT, 'users[i].photo.proidentbc0'
        EXEC sp_OAMethod @jResp, 'StringOf', @Fugiat_e_b OUT, 'users[i].photo.fugiat_e_b'
        EXEC sp_OAMethod @jResp, 'StringOf', @remote_photo_url OUT, 'users[i].remote_photo_url'
        EXEC sp_OAMethod @jResp, 'StringOf', @report_csv OUT, 'users[i].report_csv'
        EXEC sp_OAMethod @jResp, 'StringOf', @restricted_agent OUT, 'users[i].restricted_agent'
        EXEC sp_OAMethod @jResp, 'StringOf', @role OUT, 'users[i].role'
        EXEC sp_OAMethod @jResp, 'StringOf', @role_type OUT, 'users[i].role_type'
        EXEC sp_OAMethod @jResp, 'StringOf', @v_shared OUT, 'users[i].shared'
        EXEC sp_OAMethod @jResp, 'StringOf', @shared_agent OUT, 'users[i].shared_agent'
        EXEC sp_OAMethod @jResp, 'StringOf', @shared_phone_number OUT, 'users[i].shared_phone_number'
        EXEC sp_OAMethod @jResp, 'StringOf', @signature OUT, 'users[i].signature'
        EXEC sp_OAMethod @jResp, 'StringOf', @suspended OUT, 'users[i].suspended'
        EXEC sp_OAMethod @jResp, 'StringOf', @tags OUT, 'users[i].tags'
        EXEC sp_OAMethod @jResp, 'StringOf', @ticket_restriction OUT, 'users[i].ticket_restriction'
        EXEC sp_OAMethod @jResp, 'StringOf', @time_zone OUT, 'users[i].time_zone'
        EXEC sp_OAMethod @jResp, 'StringOf', @two_factor_auth_enabled OUT, 'users[i].two_factor_auth_enabled'
        EXEC sp_OAMethod @jResp, 'StringOf', @updated_at OUT, 'users[i].updated_at'
        EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'users[i].url'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Culpa14b OUT, 'users[i].user_fields.culpa14b'
        EXEC sp_OAMethod @jResp, 'StringOf', @verified OUT, 'users[i].verified'
        EXEC sp_OAMethod @jResp, 'IntOf', @In223 OUT, 'users[i].photo.in223'
        EXEC sp_OAMethod @jResp, 'StringOf', @Quis20_ OUT, 'users[i].photo.quis20_'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Aliquipe8 OUT, 'users[i].user_fields.aliquipe8'
        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  -u login:password -G -d "start_time=%3Cinteger%3E"
	-d "cursor=%3Cstring%3E"
	-d "per_page=%3Cinteger%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/incremental/users/cursor

Postman Collection Item JSON

{
  "name": "Incremental User Export, Cursor Based",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/incremental/users/cursor?start_time=<integer>&cursor=<string>&per_page=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "incremental",
        "users",
        "cursor"
      ],
      "query": [
        {
          "key": "start_time",
          "value": "<integer>",
          "description": "(Required) The time to start the incremental export from"
        },
        {
          "key": "cursor",
          "value": "<string>",
          "description": "The cursor pointer to work with for all subsequent exports after the initial request"
        },
        {
          "key": "per_page",
          "value": "<integer>",
          "description": "The number of records to return per page"
        }
      ]
    },
    "description": "#### Allowed For\n\n * Admins\n\n#### Sideloading\n\nSee [Users sideloads](/documentation/ticketing/using-the-zendesk-api/side_loading/#supported-endpoints).\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/incremental/users/cursor?start_time=<integer>&cursor=<string>&per_page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "incremental",
            "users",
            "cursor"
          ],
          "query": [
            {
              "key": "start_time",
              "value": "<integer>",
              "description": "(Required) The time to start the incremental export from"
            },
            {
              "key": "cursor",
              "value": "<string>",
              "description": "The cursor pointer to work with for all subsequent exports after the initial request"
            },
            {
              "key": "per_page",
              "value": "<integer>",
              "description": "The number of records to return per page"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"after_cursor\": \"<string>\",\n  \"after_url\": \"<string>\",\n  \"before_cursor\": \"<string>\",\n  \"before_url\": \"<string>\",\n  \"end_of_stream\": \"<boolean>\",\n  \"users\": [\n    {\n      \"name\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"alias\": \"<string>\",\n      \"chat_only\": \"<boolean>\",\n      \"created_at\": \"<string>\",\n      \"custom_role_id\": \"<integer>\",\n      \"default_group_id\": \"<integer>\",\n      \"details\": \"<string>\",\n      \"email\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"iana_time_zone\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"last_login_at\": \"<string>\",\n      \"locale\": \"<string>\",\n      \"locale_id\": \"<integer>\",\n      \"moderator\": \"<boolean>\",\n      \"notes\": \"<string>\",\n      \"only_private_comments\": \"<boolean>\",\n      \"organization_id\": \"<integer>\",\n      \"phone\": \"<string>\",\n      \"photo\": {\n        \"proidentbc0\": -29354278.707036167,\n        \"fugiat_e_b\": -98816029.91228342\n      },\n      \"remote_photo_url\": \"<string>\",\n      \"report_csv\": \"<boolean>\",\n      \"restricted_agent\": \"<boolean>\",\n      \"role\": \"<string>\",\n      \"role_type\": \"<integer>\",\n      \"shared\": \"<boolean>\",\n      \"shared_agent\": \"<boolean>\",\n      \"shared_phone_number\": \"<boolean>\",\n      \"signature\": \"<string>\",\n      \"suspended\": \"<boolean>\",\n      \"tags\": \"<array>\",\n      \"ticket_restriction\": \"<string>\",\n      \"time_zone\": \"<string>\",\n      \"two_factor_auth_enabled\": \"<boolean>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\",\n      \"user_fields\": {\n        \"culpa14b\": true\n      },\n      \"verified\": \"<boolean>\"\n    },\n    {\n      \"name\": \"<string>\",\n      \"active\": \"<boolean>\",\n      \"alias\": \"<string>\",\n      \"chat_only\": \"<boolean>\",\n      \"created_at\": \"<string>\",\n      \"custom_role_id\": \"<integer>\",\n      \"default_group_id\": \"<integer>\",\n      \"details\": \"<string>\",\n      \"email\": \"<string>\",\n      \"external_id\": \"<string>\",\n      \"iana_time_zone\": \"<string>\",\n      \"id\": \"<integer>\",\n      \"last_login_at\": \"<string>\",\n      \"locale\": \"<string>\",\n      \"locale_id\": \"<integer>\",\n      \"moderator\": \"<boolean>\",\n      \"notes\": \"<string>\",\n      \"only_private_comments\": \"<boolean>\",\n      \"organization_id\": \"<integer>\",\n      \"phone\": \"<string>\",\n      \"photo\": {\n        \"in223\": -78887847,\n        \"quis20_\": 61629027.23513341\n      },\n      \"remote_photo_url\": \"<string>\",\n      \"report_csv\": \"<boolean>\",\n      \"restricted_agent\": \"<boolean>\",\n      \"role\": \"<string>\",\n      \"role_type\": \"<integer>\",\n      \"shared\": \"<boolean>\",\n      \"shared_agent\": \"<boolean>\",\n      \"shared_phone_number\": \"<boolean>\",\n      \"signature\": \"<string>\",\n      \"suspended\": \"<boolean>\",\n      \"tags\": \"<array>\",\n      \"ticket_restriction\": \"<string>\",\n      \"time_zone\": \"<string>\",\n      \"two_factor_auth_enabled\": \"<boolean>\",\n      \"updated_at\": \"<string>\",\n      \"url\": \"<string>\",\n      \"user_fields\": {\n        \"aliquipe8\": false\n      },\n      \"verified\": \"<boolean>\"\n    }\n  ]\n}"
    }
  ]
}