Unicode C Google Calendar: Update (Patch) a Calendar Entry

Back to Index

Updates an entry on the user's calendar list.
This example updates the "summary" for the calendar having the ID = "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com". The new summary will be "Party Calendar".

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/patch


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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkOAuth2W oauth2;
    HCkJsonObjectW jsonReq;
    HCkStringBuilderW sbReq;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    const wchar_t *kind;
    const wchar_t *etag;
    const wchar_t *id;
    const wchar_t *summary;
    const wchar_t *timeZone;

    rest = CkRestW_Create();

    //   Provide a previously obtained OAuth2 access token.
    oauth2 = CkOAuth2W_Create();
    CkOAuth2W_putAccessToken(oauth2,L"OAUTH2_ACCESS_TOKEN");
    CkRestW_SetAuthOAuth2(rest,oauth2);

    success = CkRestW_Connect(rest,L"www.googleapis.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        return;
    }

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    jsonReq = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonReq,L"summary",L"Party Calendar");

    sbReq = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(jsonReq,sbReq);

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

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"PATCH",L"/calendar/v3/calendars/chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",sbReq,sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.

    kind = CkJsonObjectW_stringOf(json,L"kind");
    etag = CkJsonObjectW_stringOf(json,L"etag");
    id = CkJsonObjectW_stringOf(json,L"id");
    summary = CkJsonObjectW_stringOf(json,L"summary");
    timeZone = CkJsonObjectW_stringOf(json,L"timeZone");

    wprintf(L"Example Completed.\n");


    CkRestW_Dispose(rest);
    CkOAuth2W_Dispose(oauth2);
    CkJsonObjectW_Dispose(jsonReq);
    CkStringBuilderW_Dispose(sbReq);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(json);

    }

Sample JSON Request Body

{  
"summary": "Party Calendar" 
}



  

Sample JSON Response Body

{
  "kind": "calendar#calendar",
  "etag": "\"BKjXnZpXR6E5ueFWG3UJk-2POYg/jcCkAVFAjoCovUbrUQlnks64qfY\"",
  "id": "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",
  "summary": "Party Calendar",
  "timeZone": "UTC"
}