Calendar PATCH returning 200 but not updating fields

Created on 27 February 2023, over 1 year ago
Updated 1 March 2023, over 1 year ago

The basic problem I'm having is trying to update a Calendar description. Google is returning a 200 but the field is never getting updated.
Permissions are correct. Nothing throws an error anywhere. Any thoughts?

    $google_api_service_client = \Drupal::entityTypeManager()->getStorage('google_api_service_client')->load('my_service_account');
    $googleService = \Drupal::service('google_api_service_client.client');
    $googleService->setGoogleApiClient($google_api_service_client);

    $googleService->googleClient->setSubject($calendar_id);

    $service = new \Google_Service_Calendar($googleService->googleClient);

    // THIS WORKS: This will return the calendar information fine
    $service->calendarList->get($calendar_id);

    // PROBLEM: docs say you must use PATCH semantics to update a single field. 
    // Using the following, the api returns a 200 but the field is never updated.
    $postBody = new \Google_Service_Calendar_CalendarListEntry();
    $postBody->setDescription('Some new description');
    $service->calendarList->patch($calendar_id, $postBody);
💬 Support request
Status

Closed: works as designed

Version

4.3

Component

Code

Created by

🇺🇸United States RustedBucket

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @RustedBucket
  • 🇮🇳India sadashiv

    Hi,

    I would suggest trying minor change
    Use
    $postBody = new \Google\Service\Calendar\Calendar();
    or
    $postBody = new \Google_Service_Calendar_Calendar();
    instead of
    $postBody = new \Google_Service_Calendar_CalendarListEntry();

    and the api call change to

    $service->calendars->patch($calendar_id, $postBody);

    so the final code should look like

        $google_api_service_client = \Drupal::entityTypeManager()->getStorage('google_api_service_client')->load('my_service_account');
        $googleService = \Drupal::service('google_api_service_client.client');
        $googleService->setGoogleApiClient($google_api_service_client);
    
        $googleService->googleClient->setSubject($calendar_id);
    
        $service = new \Google_Service_Calendar($googleService->googleClient);
    
        // THIS WORKS: This will return the calendar information fine
        $service->calendarList->get($calendar_id);
    
        $postBody = new \Google_Service_Calendar_Calendar();
        $postBody->setDescription('Some new description');
        $service->calendars->patch($calendar_id, $postBody);

    Hth,
    Sadashiv

  • 🇺🇸United States RustedBucket

    So using the Google_Service_Calendar_Calendar class does work. However, that set apis only exposes a very limited amount of Calendar data as compared the Google_Service_Calendar_CalendarListEntry. Not that it is a big deal but the fact one can't update via $service->calendarList->patch seems problematic. For instance, if one wanted to update the backgroundColor that isn't part of the Calendar_Calendar class so you have to use Calendar_CalendarListEntry.

    Also, is there an easy way to capture the raw request and response objects by chance?

    Thanks

  • Status changed to Closed: works as designed over 1 year ago
  • 🇮🇳India sadashiv

    Hi @RustedBucket,

    I think you are trying to operate on calendar fields so you need to use Calendar API, CalendarList is something different.
    You can read google documentations at https://developers.google.com/calendar/api/concepts/events-calendars#cal...
    https://developers.google.com/calendar/api/v3/reference/calendarList/update
    https://developers.google.com/calendar/api/v3/reference/calendars/update
    etc

    From the Documentation Description can't be set using the CalendarList but is supported only by Calendar, The php api client library has the function but that is out of the scope of this module and can be reported to the library github.

    Thanks,
    Sadashiv.

Production build 0.69.0 2024