Chilkat Online Tools

SQL Server / Support API / Incremental User Export, Time 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, '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', @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)

    -- {
    --   "count": "<integer>",
    --   "end_of_stream": "<boolean>",
    --   "end_time": "<integer>",
    --   "next_page": "<string>",
    --   "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": {
    --         "adipisicing_be": -39386977,
    --         "culpa1": true,
    --         "id63": 47671826.614892066
    --       },
    --       "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": {
    --         "Utcb6": -74003819
    --       },
    --       "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": {
    --         "Ut_4ed": 19247988,
    --         "laborum_0": true,
    --         "deserunt1c": -98204692,
    --         "enim87c": true,
    --         "ipsume0d": 97038646.85032353
    --       },
    --       "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": {
    --         "tempor_5f": false,
    --         "commodo_e": -84252164
    --       },
    --       "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 @Adipisicing_be int

    DECLARE @Culpa1 int

    DECLARE @Id63 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 @Utcb6 int

    DECLARE @verified nvarchar(4000)

    DECLARE @Ut_4ed int

    DECLARE @Laborum_0 int

    DECLARE @Deserunt1c int

    DECLARE @Enim87c int

    DECLARE @Ipsume0d nvarchar(4000)

    DECLARE @Tempor_5f int

    DECLARE @Commodo_e int

    DECLARE @count nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @count OUT, 'count'
    DECLARE @end_of_stream nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @end_of_stream OUT, 'end_of_stream'
    DECLARE @end_time nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @end_time OUT, 'end_time'
    DECLARE @next_page nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @next_page OUT, 'next_page'
    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, 'IntOf', @Adipisicing_be OUT, 'users[i].photo.adipisicing_be'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Culpa1 OUT, 'users[i].photo.culpa1'
        EXEC sp_OAMethod @jResp, 'StringOf', @Id63 OUT, 'users[i].photo.id63'
        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, 'IntOf', @Utcb6 OUT, 'users[i].user_fields.Utcb6'
        EXEC sp_OAMethod @jResp, 'StringOf', @verified OUT, 'users[i].verified'
        EXEC sp_OAMethod @jResp, 'IntOf', @Ut_4ed OUT, 'users[i].photo.Ut_4ed'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Laborum_0 OUT, 'users[i].photo.laborum_0'
        EXEC sp_OAMethod @jResp, 'IntOf', @Deserunt1c OUT, 'users[i].photo.deserunt1c'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Enim87c OUT, 'users[i].photo.enim87c'
        EXEC sp_OAMethod @jResp, 'StringOf', @Ipsume0d OUT, 'users[i].photo.ipsume0d'
        EXEC sp_OAMethod @jResp, 'BoolOf', @Tempor_5f OUT, 'users[i].user_fields.tempor_5f'
        EXEC sp_OAMethod @jResp, 'IntOf', @Commodo_e OUT, 'users[i].user_fields.commodo_e'
        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 "per_page=%3Cinteger%3E"
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/incremental/users

Postman Collection Item JSON

{
  "name": "Incremental User Export, Time Based",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/incremental/users?start_time=<integer>&per_page=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "incremental",
        "users"
      ],
      "query": [
        {
          "key": "start_time",
          "value": "<integer>",
          "description": "(Required) The time to start the incremental export from"
        },
        {
          "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?start_time=<integer>&per_page=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "incremental",
            "users"
          ],
          "query": [
            {
              "key": "start_time",
              "value": "<integer>",
              "description": "(Required) The time to start the incremental export from"
            },
            {
              "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  \"count\": \"<integer>\",\n  \"end_of_stream\": \"<boolean>\",\n  \"end_time\": \"<integer>\",\n  \"next_page\": \"<string>\",\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        \"adipisicing_be\": -39386977,\n        \"culpa1\": true,\n        \"id63\": 47671826.614892066\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        \"Utcb6\": -74003819\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        \"Ut_4ed\": 19247988,\n        \"laborum_0\": true,\n        \"deserunt1c\": -98204692,\n        \"enim87c\": true,\n        \"ipsume0d\": 97038646.85032353\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        \"tempor_5f\": false,\n        \"commodo_e\": -84252164\n      },\n      \"verified\": \"<boolean>\"\n    }\n  ]\n}"
    }
  ]
}