Perl 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

Perl Example

use chilkat();

$rest = chilkat::CkRest->new();

#  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) {
    print "ConnectFailReason: " . $rest->get_ConnectFailReason() . "\r\n";
    print $rest->lastErrorText() . "\r\n";
    exit;
}

$rest->SetAuthBasic("zendesk_email/token","zendesk_api_token");

$sbResponseBody = chilkat::CkStringBuilder->new();
$success = $rest->FullRequestNoBodySb("GET","/api/v2/users.json",$sbResponseBody);
if ($success != 1) {
    print $rest->lastErrorText() . "\r\n";
    exit;
}

$respStatusCode = $rest->get_ResponseStatusCode();
if ($respStatusCode >= 400) {
    print "Response Status Code = " . $respStatusCode . "\r\n";
    print "Response Header:" . "\r\n";
    print $rest->responseHeader() . "\r\n";
    print "Response Body:" . "\r\n";
    print $sbResponseBody->getAsString() . "\r\n";
    exit;
}

$jsonResponse = chilkat::CkJsonObject->new();
$jsonResponse->LoadSb($sbResponseBody);

$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) {
    $jsonResponse->put_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) {
        $jsonResponse->put_J($j);
        $strVal = $jsonResponse->stringOf("users[i].tags[j]");
        $j = $j + 1;
    }

    $j = 0;
    $count_j = $jsonResponse->SizeOfArray("users[i].photo.thumbnails");
    while ($j < $count_j) {
        $jsonResponse->put_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;
    }

    $i = $i + 1;
}

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
}