Chilkat Online Tools

unicodeC / Support API / Show Self

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *Name;
    const wchar_t *Active;
    const wchar_t *Alias;
    const wchar_t *Chat_only;
    const wchar_t *Created_at;
    const wchar_t *Custom_role_id;
    const wchar_t *Default_group_id;
    const wchar_t *Details;
    const wchar_t *v_Email;
    const wchar_t *External_id;
    const wchar_t *Iana_time_zone;
    const wchar_t *Id;
    const wchar_t *Last_login_at;
    const wchar_t *Locale;
    const wchar_t *Locale_id;
    const wchar_t *Moderator;
    const wchar_t *Notes;
    const wchar_t *Only_private_comments;
    const wchar_t *Organization_id;
    const wchar_t *Phone;
    const wchar_t *Dolore50;
    const wchar_t *Remote_photo_url;
    const wchar_t *Report_csv;
    const wchar_t *Restricted_agent;
    const wchar_t *Role;
    const wchar_t *Role_type;
    const wchar_t *v_Shared;
    const wchar_t *Shared_agent;
    const wchar_t *Shared_phone_number;
    const wchar_t *Signature;
    const wchar_t *Suspended;
    const wchar_t *Tags;
    const wchar_t *Ticket_restriction;
    const wchar_t *Time_zone;
    const wchar_t *Two_factor_auth_enabled;
    const wchar_t *Updated_at;
    const wchar_t *v_Url;
    int Deserunt_c4;
    const wchar_t *Verified;
    const wchar_t *Authenticity_token;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    CkHttpW_putBasicAuth(http,TRUE);
    CkHttpW_putLogin(http,L"login");
    CkHttpW_putPassword(http,L"password");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://example.zendesk.com/api/v2/users/me",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "user": {
    //     "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": {
    //       "dolore50": -51881550.25541992
    //     },
    //     "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": {
    //       "deserunt_c4": -61141403
    //     },
    //     "verified": "<boolean>",
    //     "authenticity_token": "<string>"
    //   }
    // }

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

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Name = CkJsonObjectW_stringOf(jResp,L"user.name");
    Active = CkJsonObjectW_stringOf(jResp,L"user.active");
    Alias = CkJsonObjectW_stringOf(jResp,L"user.alias");
    Chat_only = CkJsonObjectW_stringOf(jResp,L"user.chat_only");
    Created_at = CkJsonObjectW_stringOf(jResp,L"user.created_at");
    Custom_role_id = CkJsonObjectW_stringOf(jResp,L"user.custom_role_id");
    Default_group_id = CkJsonObjectW_stringOf(jResp,L"user.default_group_id");
    Details = CkJsonObjectW_stringOf(jResp,L"user.details");
    v_Email = CkJsonObjectW_stringOf(jResp,L"user.email");
    External_id = CkJsonObjectW_stringOf(jResp,L"user.external_id");
    Iana_time_zone = CkJsonObjectW_stringOf(jResp,L"user.iana_time_zone");
    Id = CkJsonObjectW_stringOf(jResp,L"user.id");
    Last_login_at = CkJsonObjectW_stringOf(jResp,L"user.last_login_at");
    Locale = CkJsonObjectW_stringOf(jResp,L"user.locale");
    Locale_id = CkJsonObjectW_stringOf(jResp,L"user.locale_id");
    Moderator = CkJsonObjectW_stringOf(jResp,L"user.moderator");
    Notes = CkJsonObjectW_stringOf(jResp,L"user.notes");
    Only_private_comments = CkJsonObjectW_stringOf(jResp,L"user.only_private_comments");
    Organization_id = CkJsonObjectW_stringOf(jResp,L"user.organization_id");
    Phone = CkJsonObjectW_stringOf(jResp,L"user.phone");
    Dolore50 = CkJsonObjectW_stringOf(jResp,L"user.photo.dolore50");
    Remote_photo_url = CkJsonObjectW_stringOf(jResp,L"user.remote_photo_url");
    Report_csv = CkJsonObjectW_stringOf(jResp,L"user.report_csv");
    Restricted_agent = CkJsonObjectW_stringOf(jResp,L"user.restricted_agent");
    Role = CkJsonObjectW_stringOf(jResp,L"user.role");
    Role_type = CkJsonObjectW_stringOf(jResp,L"user.role_type");
    v_Shared = CkJsonObjectW_stringOf(jResp,L"user.shared");
    Shared_agent = CkJsonObjectW_stringOf(jResp,L"user.shared_agent");
    Shared_phone_number = CkJsonObjectW_stringOf(jResp,L"user.shared_phone_number");
    Signature = CkJsonObjectW_stringOf(jResp,L"user.signature");
    Suspended = CkJsonObjectW_stringOf(jResp,L"user.suspended");
    Tags = CkJsonObjectW_stringOf(jResp,L"user.tags");
    Ticket_restriction = CkJsonObjectW_stringOf(jResp,L"user.ticket_restriction");
    Time_zone = CkJsonObjectW_stringOf(jResp,L"user.time_zone");
    Two_factor_auth_enabled = CkJsonObjectW_stringOf(jResp,L"user.two_factor_auth_enabled");
    Updated_at = CkJsonObjectW_stringOf(jResp,L"user.updated_at");
    v_Url = CkJsonObjectW_stringOf(jResp,L"user.url");
    Deserunt_c4 = CkJsonObjectW_IntOf(jResp,L"user.user_fields.deserunt_c4");
    Verified = CkJsonObjectW_stringOf(jResp,L"user.verified");
    Authenticity_token = CkJsonObjectW_stringOf(jResp,L"user.authenticity_token");


    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/users/me

Postman Collection Item JSON

{
  "name": "Show Self",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/users/me",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "users",
        "me"
      ]
    },
    "description": "#### Allowed For\n\n* Anonymous users\n\n#### Authenticity Token\n\nThe endpoint returns an `authenticity_token`. Zendesk API calls made by end users from a Zendesk help center must include this token in the `X-CSRF-Token` HTTP header. This helps prevent [cross-site request forgery (CSRF)](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks.\n\nFor an example using an authenticity token, see the AJAX request in the [Upgrading from Templating API v1](https://developer.zendesk.com/documentation/help_center/help-center-templates/v1#jquery) documentation.\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/users/me",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "users",
            "me"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"user\": {\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      \"dolore50\": -51881550.25541992\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      \"deserunt_c4\": -61141403\n    },\n    \"verified\": \"<boolean>\",\n    \"authenticity_token\": \"<string>\"\n  }\n}"
    }
  ]
}