in Education by
I am retrieving messages from an Outlook account. I am trying to get inline files and attachments from those messages. $graph = new Graph(); $graph->setAccessToken($this->getAccessToken()); $messageQueryParams = array ( "\$select" => "subject,receivedDateTime,from,sentDateTime,body,toRecipients,sender,uniqueBody,ccRecipients,bccRecipients,attachments", "\$orderby" => "receivedDateTime DESC", "\$top" => "200" ); $url = '/me/mailfolders/' . $folder . '/messages/delta'; $url_combiner = '?'; $getMessagesUrl = $url . $url_combiner . http_build_query($messageQueryParams); $response = $graph->createRequest('GET', $getMessagesUrl)->execute(); $messages = $response->getResponseAsObject( \Microsoft\Graph\Model\Message::class ); foreach($messages as $msg) { echo $msg->getHasAttachments(); } This code returns 'null' for $msg->getHasAttachments(); I would expect it to return a true or false. The messages I am downloading from this folder have both inline attachments and mail attachments, so I am looking for a solution to both. (Responses that point to specific points in the MS Graph PHP SDK documentation are very appreciated.) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is the expected behavior, in your case getHasAttachments() method returns null since hasAttachments is not included in $select query option and therefore it is not requested from a server. It needs to be explicitly included, for example: $messageQueryParams = array ( "\$select" => "hasAttachments,...", //another params are omitted for clarity ); Then whether a message contains attachments or not could be determined like this: foreach($messages as $msg) { if($msg->getHasAttachments() == true){ //... } There is one more issue with the provided example, to retrieve Message.attachments reference property (or relationship property) it needs to be specified via $expand query string parameter instead of $select (refer official documentation for a more details), like this: $messageQueryParams = array ( "\$expand" => "attachments", //another params are omitted for clarity ); Then attachments collection could be iterated like this: foreach($messages as $msg) { foreach($msg->getAttachments() as $attachment) { //... } }

Related questions

0 votes
    My code cannot display the permission dialog when a user connect to my Facebook application. Instead of the login page, I ... getLoginUrl(array( 'scope' => 'publish_stream', )); }...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have been using php-sdk to connect to facebook for a while and I never had any problems, but ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am struggling trying to update a row in an Azure SQL database. What I am trying to do is to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    As I understand it, if there are only messages with a timestamp for the future in a MessageQueue, the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    What happen if we send any message to an object which is released?...
asked Nov 10, 2020 in Technology by JackTerrance
0 votes
    I know we can send a message from within an iPhone app, but I want to check the reachability of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    I know we can send a message from within an iPhone app, but I want to check the reachability of ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    I have an aspnetboilerplate template, .netcore & angular (free version). I am trying to find a way ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    We have created a web application, using ASP.NET, that allows users to upload documents and attach them to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    I'm getting into user scripting with tampermonkey and can't get through this error, any help would be ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    There are three boxes in a table. One of the box contains Gold and the other two are empty. A printed message contains in ... Gold is in the Second box'. Which box has the Gold?...
asked Feb 10, 2021 in Education by JackTerrance
...