How to handle JSON-Return Object/Array (PHP), e.g. calendar request

Daniel Bäuerlein 1 Reputation point
2022-01-31T09:17:12.977+00:00

Hi,

another day, another question ;-)

How can i handle the JSON Response of e.g. a calendar Request like this:

$termine = $graph->createRequest("GET", "/users/my@tiedtlaw email .de/calendarView?startdatetime=2022-01-28T08:00:00&enddatetime=2022-01-28T20:00:00")
->setReturnType(Model\Calendar::class)
->execute();

How can i return for eaxample the subject or the body?

This was my try, i commented, what works and what not:

foreach ($termine as $termin) {
//$subject=$termin->subject; // Does not work
//$subject=$termin->getSubject(); // Does not work
//$subject=$termin["subject"]; // Does not work
echo "ID:".$termin->getId(); //Works
}

Is there a documentation of how to access the JSON-Array?

Best wishes
Daniel

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JanardhanaVedham-MSFT 3,581 Reputation points
    2022-01-31T13:17:32.693+00:00

    Hi @Daniel Bäuerlein ,

    You can directly use $select OData Query Parameter to fetch the required event properies with Microsoft Graph List calendarView API.

    Note : The createdDateTime and lastModifiedDateTime properties of event do not support $select. To get their values, simply query on calendarView without applying $select.

    GET https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/calendarView?startdatetime=2022-01-01T08:00:00&enddatetime=2022-01-31T20:00:00&$select=Id,subject,body  
    

    Example :

    https://graph.microsoft.com/v1.0/users/******@o365XXX.onmicrosoft.com/calendarView?startdatetime=2022-01-01T08:00:00&enddatetime=2022-01-31T20:00:00&$select=Id,subject,body  
    

    169829-image.png

    Also, you can try to use "Model\Event::class" parameter in setReturnType() function as mentioned in this calender view PHP SDK example.
    170163-image.png
    Display of the event data in the UI :
    170136-image.png

    Addtional References (please refer the below documentation for more information on event properies & resource :
    https://learn.microsoft.com/en-us/graph/api/user-list-calendarview?view=graph-rest-1.0&tabs=http#query-parameters
    https://learn.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0#properties
    https://learn.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have any further questions about this answer, please click "Comment".

    1 person found this answer helpful.

  2. Daniel Baeuerlein 61 Reputation points
    2022-02-02T11:50:26.64+00:00

    Hi,

    thath would be nice.
    As you see, again i have a new user ID, this time DanielBaeuerlein-5192.
    Ang again i logged in with the same username (my email-adress) and the same password that i used for the original question.
    This is so strange and annoying ;-(

    Best wishes and have a nice day.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.