Unicode C Zendesk: Update user

Back to Index

Update a user by user ID. This example updates the user with id = 361811376954

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

CURL Command

curl https://subdomain.zendesk.com/api/v2/users/361811376954.json \
  -d '{"user": {"name": "Roger Wilco II"}}' \
  -H "Content-Type: application/json" -X PUT \
  -u zendesk_email/token:zendesk_api_token

Unicode C Example

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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jsonResponse;
    int userId;
    const wchar_t *userUrl;
    const wchar_t *userName;
    const wchar_t *userEmail;
    const wchar_t *userCreated_at;
    const wchar_t *userUpdated_at;
    const wchar_t *userTime_zone;
    const wchar_t *userPhone;
    const wchar_t *userShared_phone_number;
    const wchar_t *userPhoto;
    int userLocale_id;
    const wchar_t *userLocale;
    const wchar_t *userOrganization_id;
    const wchar_t *userRole;
    BOOL userVerified;
    const wchar_t *userExternal_id;
    const wchar_t *userAlias;
    BOOL userActive;
    BOOL userShared;
    BOOL userShared_agent;
    const wchar_t *userLast_login_at;
    BOOL userTwo_factor_auth_enabled;
    const wchar_t *userSignature;
    const wchar_t *userDetails;
    const wchar_t *userNotes;
    const wchar_t *userRole_type;
    const wchar_t *userCustom_role_id;
    BOOL userModerator;
    const wchar_t *userTicket_restriction;
    BOOL userOnly_private_comments;
    BOOL userRestricted_agent;
    BOOL userSuspended;
    BOOL userChat_only;
    const wchar_t *userDefault_group_id;
    int i;
    int count_i;

    rest = CkRestW_Create();

    //  URL: https://subdomain.zendesk.com/api/v2/users/361811376954.json
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"subdomain.zendesk.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

    CkRestW_SetAuthBasic(rest,L"zendesk_email/token",L"zendesk_api_token");

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"user.name",L"Roger Wilco II");

    CkRestW_AddHeader(rest,L"Content-Type",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"PUT",L"/api/v2/users/361811376954.json",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jsonResponse,sbResponseBody);

    userId = CkJsonObjectW_IntOf(jsonResponse,L"user.id");
    userUrl = CkJsonObjectW_stringOf(jsonResponse,L"user.url");
    userName = CkJsonObjectW_stringOf(jsonResponse,L"user.name");
    userEmail = CkJsonObjectW_stringOf(jsonResponse,L"user.email");
    userCreated_at = CkJsonObjectW_stringOf(jsonResponse,L"user.created_at");
    userUpdated_at = CkJsonObjectW_stringOf(jsonResponse,L"user.updated_at");
    userTime_zone = CkJsonObjectW_stringOf(jsonResponse,L"user.time_zone");
    userPhone = CkJsonObjectW_stringOf(jsonResponse,L"user.phone");
    userShared_phone_number = CkJsonObjectW_stringOf(jsonResponse,L"user.shared_phone_number");
    userPhoto = CkJsonObjectW_stringOf(jsonResponse,L"user.photo");
    userLocale_id = CkJsonObjectW_IntOf(jsonResponse,L"user.locale_id");
    userLocale = CkJsonObjectW_stringOf(jsonResponse,L"user.locale");
    userOrganization_id = CkJsonObjectW_stringOf(jsonResponse,L"user.organization_id");
    userRole = CkJsonObjectW_stringOf(jsonResponse,L"user.role");
    userVerified = CkJsonObjectW_BoolOf(jsonResponse,L"user.verified");
    userExternal_id = CkJsonObjectW_stringOf(jsonResponse,L"user.external_id");
    userAlias = CkJsonObjectW_stringOf(jsonResponse,L"user.alias");
    userActive = CkJsonObjectW_BoolOf(jsonResponse,L"user.active");
    userShared = CkJsonObjectW_BoolOf(jsonResponse,L"user.shared");
    userShared_agent = CkJsonObjectW_BoolOf(jsonResponse,L"user.shared_agent");
    userLast_login_at = CkJsonObjectW_stringOf(jsonResponse,L"user.last_login_at");
    userTwo_factor_auth_enabled = CkJsonObjectW_BoolOf(jsonResponse,L"user.two_factor_auth_enabled");
    userSignature = CkJsonObjectW_stringOf(jsonResponse,L"user.signature");
    userDetails = CkJsonObjectW_stringOf(jsonResponse,L"user.details");
    userNotes = CkJsonObjectW_stringOf(jsonResponse,L"user.notes");
    userRole_type = CkJsonObjectW_stringOf(jsonResponse,L"user.role_type");
    userCustom_role_id = CkJsonObjectW_stringOf(jsonResponse,L"user.custom_role_id");
    userModerator = CkJsonObjectW_BoolOf(jsonResponse,L"user.moderator");
    userTicket_restriction = CkJsonObjectW_stringOf(jsonResponse,L"user.ticket_restriction");
    userOnly_private_comments = CkJsonObjectW_BoolOf(jsonResponse,L"user.only_private_comments");
    userRestricted_agent = CkJsonObjectW_BoolOf(jsonResponse,L"user.restricted_agent");
    userSuspended = CkJsonObjectW_BoolOf(jsonResponse,L"user.suspended");
    userChat_only = CkJsonObjectW_BoolOf(jsonResponse,L"user.chat_only");
    userDefault_group_id = CkJsonObjectW_stringOf(jsonResponse,L"user.default_group_id");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jsonResponse,L"user.tags");
    while (i < count_i) {
        CkJsonObjectW_putI(jsonResponse,i);
        i = i + 1;
    }



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jsonResponse);

    }

Sample JSON Response Body

{
  "user": {
    "id": 361811376954,
    "url": "https://chilkat.zendesk.com/api/v2/users/361811376954.json",
    "name": "Roger Wilco II",
    "email": "roger@chilkat.io",
    "created_at": "2018-04-14T23:09:24Z",
    "updated_at": "2018-04-15T02:58:06Z",
    "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": {}
  }
}