PowerBuilder 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


integer li_rc
oleobject loo_Rest
integer li_Success
oleobject loo_Oauth2
oleobject loo_JsonReq
oleobject loo_SbReq
oleobject loo_SbJson
oleobject loo_Json
string ls_Kind
string ls_Etag
string ls_Id
string ls_Summary
string ls_TimeZone

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//   Provide a previously obtained OAuth2 access token.
loo_Oauth2 = create oleobject
li_rc = loo_Oauth2.ConnectToNewObject("Chilkat_9_5_0.OAuth2")

loo_Oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loo_Rest.SetAuthOAuth2(loo_Oauth2)

li_Success = loo_Rest.Connect("www.googleapis.com",443,1,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    return
end if

//  The following code creates the JSON request body.
//  The JSON created by this code is shown below.
loo_JsonReq = create oleobject
li_rc = loo_JsonReq.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonReq.UpdateString("summary","Party Calendar")

loo_SbReq = create oleobject
li_rc = loo_SbReq.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_JsonReq.EmitSb(loo_SbReq)

loo_Rest.AddHeader("Content-Type","application/json")

loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestSb("PATCH","/calendar/v3/calendars/chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",loo_SbReq,loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_JsonReq
    destroy loo_SbReq
    destroy loo_SbJson
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response body:"
    Write-Debug loo_SbJson.GetAsString()
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_JsonReq
    destroy loo_SbReq
    destroy loo_SbJson
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.LoadSb(loo_SbJson)

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

ls_Kind = loo_Json.StringOf("kind")
ls_Etag = loo_Json.StringOf("etag")
ls_Id = loo_Json.StringOf("id")
ls_Summary = loo_Json.StringOf("summary")
ls_TimeZone = loo_Json.StringOf("timeZone")

Write-Debug "Example Completed."


destroy loo_Rest
destroy loo_Oauth2
destroy loo_JsonReq
destroy loo_SbReq
destroy loo_SbJson
destroy loo_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"
}