Visual FoxPro Zendesk: List Users

Back to Index

List users, returning a maximum of 100 users per page.

Documentation: https://developer.zendesk.com/rest_api/docs/core/users#list-users

CURL Command

curl https://subdomain.zendesk.com/api/v2/users.json \
  -u zendesk_email/token:zendesk_api_token

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL lcNext_page
LOCAL lcPrevious_page
LOCAL lnCount
LOCAL i
LOCAL lnCount_i
LOCAL lnId
LOCAL lcUrl
LOCAL lcName
LOCAL lcEmail
LOCAL lcCreated_at
LOCAL lcUpdated_at
LOCAL lcTime_zone
LOCAL lcPhone
LOCAL lcShared_phone_number
LOCAL lcPhoto
LOCAL lnLocale_id
LOCAL lcLocale
LOCAL lnOrganization_id
LOCAL lcRole
LOCAL lnVerified
LOCAL lcExternal_id
LOCAL lcAlias
LOCAL lnActive
LOCAL lnShared
LOCAL lnShared_agent
LOCAL lcLast_login_at
LOCAL lcTwo_factor_auth_enabled
LOCAL lcSignature
LOCAL lcDetails
LOCAL lcNotes
LOCAL lcRole_type
LOCAL lcCustom_role_id
LOCAL lnModerator
LOCAL lcTicket_restriction
LOCAL lnOnly_private_comments
LOCAL lnRestricted_agent
LOCAL lnSuspended
LOCAL lnChat_only
LOCAL lnDefault_group_id
LOCAL lcPhotoUrl
LOCAL lnPhotoId
LOCAL lcPhotoFile_name
LOCAL lcPhotoContent_url
LOCAL lcPhotoMapped_content_url
LOCAL lcPhotoContent_type
LOCAL lnPhotoSize
LOCAL lnPhotoWidth
LOCAL lnPhotoHeight
LOCAL lnPhotoInline
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal
LOCAL lcFile_name
LOCAL lcContent_url
LOCAL lcMapped_content_url
LOCAL lcContent_type
LOCAL lnSize
LOCAL lnWidth
LOCAL lnHeight
LOCAL lnInline

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://subdomain.zendesk.com/api/v2/users.json
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("subdomain.zendesk.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("zendesk_email/token","zendesk_api_token")

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/api/v2/users.json",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
    ? "Response Status Code = " + STR(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcNext_page = loJsonResponse.StringOf("next_page")
lcPrevious_page = loJsonResponse.StringOf("previous_page")
lnCount = loJsonResponse.IntOf("count")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("users")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lnId = loJsonResponse.IntOf("users[i].id")
    lcUrl = loJsonResponse.StringOf("users[i].url")
    lcName = loJsonResponse.StringOf("users[i].name")
    lcEmail = loJsonResponse.StringOf("users[i].email")
    lcCreated_at = loJsonResponse.StringOf("users[i].created_at")
    lcUpdated_at = loJsonResponse.StringOf("users[i].updated_at")
    lcTime_zone = loJsonResponse.StringOf("users[i].time_zone")
    lcPhone = loJsonResponse.StringOf("users[i].phone")
    lcShared_phone_number = loJsonResponse.StringOf("users[i].shared_phone_number")
    lcPhoto = loJsonResponse.StringOf("users[i].photo")
    lnLocale_id = loJsonResponse.IntOf("users[i].locale_id")
    lcLocale = loJsonResponse.StringOf("users[i].locale")
    lnOrganization_id = loJsonResponse.IntOf("users[i].organization_id")
    lcRole = loJsonResponse.StringOf("users[i].role")
    lnVerified = loJsonResponse.BoolOf("users[i].verified")
    lcExternal_id = loJsonResponse.StringOf("users[i].external_id")
    lcAlias = loJsonResponse.StringOf("users[i].alias")
    lnActive = loJsonResponse.BoolOf("users[i].active")
    lnShared = loJsonResponse.BoolOf("users[i].shared")
    lnShared_agent = loJsonResponse.BoolOf("users[i].shared_agent")
    lcLast_login_at = loJsonResponse.StringOf("users[i].last_login_at")
    lcTwo_factor_auth_enabled = loJsonResponse.StringOf("users[i].two_factor_auth_enabled")
    lcSignature = loJsonResponse.StringOf("users[i].signature")
    lcDetails = loJsonResponse.StringOf("users[i].details")
    lcNotes = loJsonResponse.StringOf("users[i].notes")
    lcRole_type = loJsonResponse.StringOf("users[i].role_type")
    lcCustom_role_id = loJsonResponse.StringOf("users[i].custom_role_id")
    lnModerator = loJsonResponse.BoolOf("users[i].moderator")
    lcTicket_restriction = loJsonResponse.StringOf("users[i].ticket_restriction")
    lnOnly_private_comments = loJsonResponse.BoolOf("users[i].only_private_comments")
    lnRestricted_agent = loJsonResponse.BoolOf("users[i].restricted_agent")
    lnSuspended = loJsonResponse.BoolOf("users[i].suspended")
    lnChat_only = loJsonResponse.BoolOf("users[i].chat_only")
    lnDefault_group_id = loJsonResponse.IntOf("users[i].default_group_id")
    lcPhotoUrl = loJsonResponse.StringOf("users[i].photo.url")
    lnPhotoId = loJsonResponse.IntOf("users[i].photo.id")
    lcPhotoFile_name = loJsonResponse.StringOf("users[i].photo.file_name")
    lcPhotoContent_url = loJsonResponse.StringOf("users[i].photo.content_url")
    lcPhotoMapped_content_url = loJsonResponse.StringOf("users[i].photo.mapped_content_url")
    lcPhotoContent_type = loJsonResponse.StringOf("users[i].photo.content_type")
    lnPhotoSize = loJsonResponse.IntOf("users[i].photo.size")
    lnPhotoWidth = loJsonResponse.IntOf("users[i].photo.width")
    lnPhotoHeight = loJsonResponse.IntOf("users[i].photo.height")
    lnPhotoInline = loJsonResponse.BoolOf("users[i].photo.inline")
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("users[i].tags")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        lcStrVal = loJsonResponse.StringOf("users[i].tags[j]")
        j = j + 1
    ENDDO
    j = 0
    lnCount_j = loJsonResponse.SizeOfArray("users[i].photo.thumbnails")
    DO WHILE j < lnCount_j
        loJsonResponse.J = j
        lcUrl = loJsonResponse.StringOf("users[i].photo.thumbnails[j].url")
        lnId = loJsonResponse.IntOf("users[i].photo.thumbnails[j].id")
        lcFile_name = loJsonResponse.StringOf("users[i].photo.thumbnails[j].file_name")
        lcContent_url = loJsonResponse.StringOf("users[i].photo.thumbnails[j].content_url")
        lcMapped_content_url = loJsonResponse.StringOf("users[i].photo.thumbnails[j].mapped_content_url")
        lcContent_type = loJsonResponse.StringOf("users[i].photo.thumbnails[j].content_type")
        lnSize = loJsonResponse.IntOf("users[i].photo.thumbnails[j].size")
        lnWidth = loJsonResponse.IntOf("users[i].photo.thumbnails[j].width")
        lnHeight = loJsonResponse.IntOf("users[i].photo.thumbnails[j].height")
        lnInline = loJsonResponse.BoolOf("users[i].photo.thumbnails[j].inline")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

{
  "users": [
    {
      "id": 361801727573,
      "url": "https://chilkat.zendesk.com/api/v2/users/361801727573.json",
      "name": "Matt Fausey",
      "email": "admin@chilkatsoft.com",
      "created_at": "2018-04-14T19:01:56Z",
      "updated_at": "2018-04-14T23:09:24Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": 360015071793,
      "role": "admin",
      "verified": true,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": "2018-04-14T23:09:24Z",
      "two_factor_auth_enabled": null,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": true,
      "ticket_restriction": null,
      "only_private_comments": false,
      "restricted_agent": false,
      "suspended": false,
      "chat_only": false,
      "default_group_id": 360000681553,
      "user_fields": {}
    },
    {
      "id": 361809055094,
      "url": "https://chilkat.zendesk.com/api/v2/users/361809055094.json",
      "name": "Sample customer",
      "email": "customer@example.com",
      "created_at": "2018-04-14T19:01:56Z",
      "updated_at": "2018-04-14T19:01:57Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": {
        "url": "https://chilkat.zendesk.com/api/v2/attachments/360103279093.json",
        "id": 360103279093,
        "file_name": "profile_image_361809055094_2287229.jpg",
        "content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229.jpg",
        "mapped_content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229.jpg",
        "content_type": "image/jpeg",
        "size": 2587,
        "width": 40,
        "height": 40,
        "inline": false,
        "thumbnails": [
          {
            "url": "https://chilkat.zendesk.com/api/v2/attachments/360103279113.json",
            "id": 360103279113,
            "file_name": "profile_image_361809055094_2287229_thumb.jpg",
            "content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229_thumb.jpg",
            "mapped_content_url": "https://chilkat.zendesk.com/system/photos/3601/0327/9093/profile_image_361809055094_2287229_thumb.jpg",
            "content_type": "image/jpeg",
            "size": 1980,
            "width": 32,
            "height": 32,
            "inline": false
          }
        ]
      },
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": null,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    },
    {
      "id": 361810194934,
      "url": "https://chilkat.zendesk.com/api/v2/users/361810194934.json",
      "name": "matt",
      "email": "matt@chilkat.io",
      "created_at": "2018-04-14T20:58:33Z",
      "updated_at": "2018-04-14T20:59:40Z",
      "time_zone": "Central Time (US & Canada)",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": 360015071793,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
        "lizard",
        "gecko"
      ],
      "alias": "",
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": "",
      "notes": "Likes coffee",
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    },
    {
      "id": 361811376954,
      "url": "https://chilkat.zendesk.com/api/v2/users/361811376954.json",
      "name": "Roger Wilco",
      "email": "roger@chilkat.io",
      "created_at": "2018-04-14T23:09:24Z",
      "updated_at": "2018-04-14T23:09:24Z",
      "time_zone": "Bogota",
      "phone": null,
      "shared_phone_number": null,
      "photo": null,
      "locale_id": 1,
      "locale": "en-US",
      "organization_id": null,
      "role": "end-user",
      "verified": false,
      "external_id": null,
      "tags": [
      ],
      "alias": null,
      "active": true,
      "shared": false,
      "shared_agent": false,
      "last_login_at": null,
      "two_factor_auth_enabled": false,
      "signature": null,
      "details": null,
      "notes": null,
      "role_type": null,
      "custom_role_id": null,
      "moderator": false,
      "ticket_restriction": "requested",
      "only_private_comments": false,
      "restricted_agent": true,
      "suspended": false,
      "chat_only": false,
      "default_group_id": null,
      "user_fields": {}
    }
  ],
  "next_page": null,
  "previous_page": null,
  "count": 4
}