0
votes

I am doing callout from salesforce to google calendar api to upsert a google event. when i make the request, it always changes the attendee status to "NeedsAction", so when I sent request to google, attendee status was "Accepted" but in response i got "NeedsAction". Why google always changes the attendee response. Please help if anyone knows. Thanks

Request Body :

{
  "kind" : "calendar#event",
  "summary" : "nice 13 val",
  "description" : "this is new",
  "location" : "3 value friday",
  "start" : {
    "dateTime" : "2020-08-13T12:30:00+05:00"
  },
  "end" : {
    "dateTime" : "2020-08-13T13:30:00+05:00"
  },
  "attendees" : [ {
    "email" : "[email protected]",
    "organizer" : true,
    "responseStatus" : "accepted"
  }, {
    "email" : "[email protected]",
    "responseStatus" : "accepted"
  } ]
}

Callout :

Http http = new Http();
HttpRequest httpReq = new HttpRequest();
            httpReq.setEndpoint('https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/'+objEvent.Google_Event_Id__c);
httpReq.setTimeout(30000);
 httpReq.setHeader('Content-Type', 'application/json');
 httpReq.setMethod('POST');
 httpReq.setHeader('X-HTTP-Method-Override','PATCH');
 httpReq.setHeader('Authorization', 'Bearer ' + accessToken);
 String reqBody = createEventBody(objEvent, googleSettingInfo);
 if (String.isNotBlank(reqBody)) {
     httpReq.setBody(reqBody);
 }
if (httpReq.getBody() != null && httpReq.getBody() != '') {

    HttpResponse httpRes = http.send(httpReq);
    System.debug('code: ' + httpRes.getStatusCode());
    if (httpRes.getStatusCode() == 200) {
        System.debug('response: ' + httpRes);
        System.debug('create event response body: ' + httpRes.getBody());
    }
}

getting attendees response always as "needs Action" while this should be "accepted" for "[email protected]"

{
 
 "created": "2020-08-11T18:51:41.000Z",
 "updated": "2020-08-28T06:48:49.972Z",
 "summary": "nice 13 val",
 "description": "this is new",
 "location": "3 value friday",
 "creator": {
  "email": "[email protected]",
  "self": true
 },
 "organizer": {
  "email": "[email protected]",
  "self": true
 },
 "start": {
  "dateTime": "2020-08-13T14:00:00+05:30"
 },
 "end": {
  "dateTime": "2020-08-13T15:00:00+05:30"
 },
 "sequence": 16,
 "attendees": [
  {
   "email": "[email protected]",
   "responseStatus": "needsAction"
  },
  {
   "email": "[email protected]",
   "organizer": true,
   "self": true,
   "responseStatus": "accepted"
  }
 ],
1

1 Answers

0
votes

Proposed modification:

What about modifying the createEventBody function in order to create a simple JSON object that will only contain the attendees information with the updated statuses.

This will leverage correctly the PATCH semantics and helps a lot on improving readability.

I tested it myself and your generated JSON object returns an error on the start property. Removing that will help you solve that error too. Finally I tested that passing the attendees property to the PATCH method will work as intended.

You can try using the "Try this API" functionality before actually update your code.

Reference:

Events patch