Delphi ActiveX 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

Delphi ActiveX Example

var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
sbResponseBody: TChilkatStringBuilder;
respStatusCode: Integer;
jsonResponse: TChilkatJsonObject;
next_page: WideString;
previous_page: WideString;
count: Integer;
i: Integer;
count_i: Integer;
id: Integer;
url: WideString;
name: WideString;
email: WideString;
created_at: WideString;
updated_at: WideString;
time_zone: WideString;
phone: WideString;
shared_phone_number: WideString;
photo: WideString;
locale_id: Integer;
locale: WideString;
organization_id: Integer;
role: WideString;
verified: Integer;
external_id: WideString;
alias: WideString;
active: Integer;
shared: Integer;
shared_agent: Integer;
last_login_at: WideString;
two_factor_auth_enabled: WideString;
signature: WideString;
details: WideString;
notes: WideString;
role_type: WideString;
custom_role_id: WideString;
moderator: Integer;
ticket_restriction: WideString;
only_private_comments: Integer;
restricted_agent: Integer;
suspended: Integer;
chat_only: Integer;
default_group_id: Integer;
photoUrl: WideString;
photoId: Integer;
photoFile_name: WideString;
photoContent_url: WideString;
photoMapped_content_url: WideString;
photoContent_type: WideString;
photoSize: Integer;
photoWidth: Integer;
photoHeight: Integer;
photoInline: Integer;
j: Integer;
count_j: Integer;
strVal: WideString;
file_name: WideString;
content_url: WideString;
mapped_content_url: WideString;
content_type: WideString;
size: Integer;
width: Integer;
height: Integer;
inline: Integer;

begin
rest := TChilkatRest.Create(Self);

//  URL: https://subdomain.zendesk.com/api/v2/users.json
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('subdomain.zendesk.com',port,bTls,bAutoReconnect);
if (success <> 1) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

rest.SetAuthBasic('zendesk_email/token','zendesk_api_token');

sbResponseBody := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestNoBodySb('GET','/api/v2/users.json',sbResponseBody.ControlInterface);
if (success <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;
respStatusCode := rest.ResponseStatusCode;
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(rest.ResponseHeader);
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(sbResponseBody.GetAsString());
    Exit;
  end;

jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.LoadSb(sbResponseBody.ControlInterface);

next_page := jsonResponse.StringOf('next_page');
previous_page := jsonResponse.StringOf('previous_page');
count := jsonResponse.IntOf('count');
i := 0;
count_i := jsonResponse.SizeOfArray('users');
while i < count_i do
  begin
    jsonResponse.I := i;
    id := jsonResponse.IntOf('users[i].id');
    url := jsonResponse.StringOf('users[i].url');
    name := jsonResponse.StringOf('users[i].name');
    email := jsonResponse.StringOf('users[i].email');
    created_at := jsonResponse.StringOf('users[i].created_at');
    updated_at := jsonResponse.StringOf('users[i].updated_at');
    time_zone := jsonResponse.StringOf('users[i].time_zone');
    phone := jsonResponse.StringOf('users[i].phone');
    shared_phone_number := jsonResponse.StringOf('users[i].shared_phone_number');
    photo := jsonResponse.StringOf('users[i].photo');
    locale_id := jsonResponse.IntOf('users[i].locale_id');
    locale := jsonResponse.StringOf('users[i].locale');
    organization_id := jsonResponse.IntOf('users[i].organization_id');
    role := jsonResponse.StringOf('users[i].role');
    verified := jsonResponse.BoolOf('users[i].verified');
    external_id := jsonResponse.StringOf('users[i].external_id');
    alias := jsonResponse.StringOf('users[i].alias');
    active := jsonResponse.BoolOf('users[i].active');
    shared := jsonResponse.BoolOf('users[i].shared');
    shared_agent := jsonResponse.BoolOf('users[i].shared_agent');
    last_login_at := jsonResponse.StringOf('users[i].last_login_at');
    two_factor_auth_enabled := jsonResponse.StringOf('users[i].two_factor_auth_enabled');
    signature := jsonResponse.StringOf('users[i].signature');
    details := jsonResponse.StringOf('users[i].details');
    notes := jsonResponse.StringOf('users[i].notes');
    role_type := jsonResponse.StringOf('users[i].role_type');
    custom_role_id := jsonResponse.StringOf('users[i].custom_role_id');
    moderator := jsonResponse.BoolOf('users[i].moderator');
    ticket_restriction := jsonResponse.StringOf('users[i].ticket_restriction');
    only_private_comments := jsonResponse.BoolOf('users[i].only_private_comments');
    restricted_agent := jsonResponse.BoolOf('users[i].restricted_agent');
    suspended := jsonResponse.BoolOf('users[i].suspended');
    chat_only := jsonResponse.BoolOf('users[i].chat_only');
    default_group_id := jsonResponse.IntOf('users[i].default_group_id');
    photoUrl := jsonResponse.StringOf('users[i].photo.url');
    photoId := jsonResponse.IntOf('users[i].photo.id');
    photoFile_name := jsonResponse.StringOf('users[i].photo.file_name');
    photoContent_url := jsonResponse.StringOf('users[i].photo.content_url');
    photoMapped_content_url := jsonResponse.StringOf('users[i].photo.mapped_content_url');
    photoContent_type := jsonResponse.StringOf('users[i].photo.content_type');
    photoSize := jsonResponse.IntOf('users[i].photo.size');
    photoWidth := jsonResponse.IntOf('users[i].photo.width');
    photoHeight := jsonResponse.IntOf('users[i].photo.height');
    photoInline := jsonResponse.BoolOf('users[i].photo.inline');
    j := 0;
    count_j := jsonResponse.SizeOfArray('users[i].tags');
    while j < count_j do
      begin
        jsonResponse.J := j;
        strVal := jsonResponse.StringOf('users[i].tags[j]');
        j := j + 1;
      end;

    j := 0;
    count_j := jsonResponse.SizeOfArray('users[i].photo.thumbnails');
    while j < count_j do
      begin
        jsonResponse.J := j;
        url := jsonResponse.StringOf('users[i].photo.thumbnails[j].url');
        id := jsonResponse.IntOf('users[i].photo.thumbnails[j].id');
        file_name := jsonResponse.StringOf('users[i].photo.thumbnails[j].file_name');
        content_url := jsonResponse.StringOf('users[i].photo.thumbnails[j].content_url');
        mapped_content_url := jsonResponse.StringOf('users[i].photo.thumbnails[j].mapped_content_url');
        content_type := jsonResponse.StringOf('users[i].photo.thumbnails[j].content_type');
        size := jsonResponse.IntOf('users[i].photo.thumbnails[j].size');
        width := jsonResponse.IntOf('users[i].photo.thumbnails[j].width');
        height := jsonResponse.IntOf('users[i].photo.thumbnails[j].height');
        inline := jsonResponse.BoolOf('users[i].photo.thumbnails[j].inline');
        j := j + 1;
      end;

    i := i + 1;
  end;

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
}