skip to Main Content

My company runs a web-application that reads out a shared-mailbox and shows the content to the users. It was based on PHP-EWS so far. Since we’re moving the mailbox into the Cloud, we have to migrate this application to MS-Graph.
I’ve already migrated the lion’s share of the application, but now I encounter a problem when I try to get the MIME-version of a message.

Getting the processed version of the message is no problem at all.
The Request for this would be something like:

GET /users/{mailbox-id}/mailfolders/inbox/messages/{message-id}

According to the documentation I have to add “/$value” at the end of the “normal” request to get the mime-version of the message.
This works perfectly into Microsoft’s Graph-Tester-Website. Within my application I can also request the MIME-version of an ATTACHED message without any problems (works with the same “/$value”-trick).
But if I request the MIME-Version of a (normal) NOT-ATTACHED message, I receive the following error:

Fatal error: Uncaught GuzzleHttpExceptionClientException: Client error: `GET https://graph.microsoft.com/v1.0/users/{mailbox-id}/mailfolders/inbox/messages/{message-id}/%24value` 
resulted in a `405 Method Not Allowed` response: { "error": { "code": "ErrorInvalidRequest", "message": "The OData request is not supported.", "innerEr (truncated...) in D:wwwrootvendorguzzlehttpguzzlesrcExceptionRequestException.php:113 
Stack trace: #0 D:wwwrootvendorguzzlehttpguzzlesrcMiddleware.php(66): GuzzleHttpExceptionRequestException::create(Object(GuzzleHttpPsr7Request), Object(GuzzleHttpPsr7Response)) 
#1 D:wwwrootvendorguzzlehttppromisessrcPromise.php(203): GuzzleHttpMiddleware::GuzzleHttp{closure}(Object(GuzzleHttpPsr7Response)) 
#2 D:wwwrootvendorguzzlehttppromisessrcPromise.php(156): GuzzleHttpPromisePromise::callHand in D:wwwrootvendorguzzlehttpguzzlesrcExceptionRequestException.php on line 113

I used the following code:

$graph = new Graph();
$graph->setAccessToken($tokenCache->getAccessToken());
 /** @var  $contentStream GuzzleHttpPsr7Stream */
$getMessageContentUrl = '/users/' . $mailbox . '/mailfolders/inbox/messages/' . $messageId.'/%24value';
try {
    $contentStream = $graph->createRequest('GET', $getMessageContentUrl)
            ->setReturnType("GuzzleHttpPsr7Stream")
            ->execute();
} catch (GraphException $e) {
            [...]
}

return $contentStream->getContents();

The same code works if I request the MIME-version of an attached message.

I thought at urlencoding-issues, so I tried “/$value” and “/%24value”, same result.

I don’t think that it is a permission problem. The OAUTH_SCOPES are

'openid profile offline_access User.Read Mail.Read Mail.Read.Shared Mail.ReadWrite Mail.ReadWrite.Shared Calendars.Read Calendars.Read.Shared'

So I think the account should have more than enough permissions to fulfill this task.

I have no idea, if I am doing something wrong or if it is a problem of the Graph-API or the Graph-PHP-SDK or the Guzzle-Http-Client.
I’m using the following versions:

“name”: “microsoft/microsoft-graph”,
“version”: “1.11.0”,

“name”: “guzzlehttp/guzzle”,
“version”: “6.3.3”,

“name”: “guzzlehttp/psr7”,
“version”: “1.6.1”,

I would be very glad if someone could help me or at least set me on the right track.

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution. Had to replace

    GET /users/{mailbox-id}/mailfolders/inbox/messages/{message-id}/$value
    

    by

    GET /users/{mailbox-id}/messages/{message-id}/$value
    

    then it works. Kind of strange that other requests with "/mailfolders/inbox/" worked, but this one not. Whatever, as long as it works.


  2. The Method Not Allowed Error means that the route you are requesting exists but not for the method you are using(GET). Try replacing GET method to POST like:

    $contentStream = $graph->createRequest('POST', $getMessageContentUrl)
            ->setReturnType("GuzzleHttpPsr7Stream")
            ->execute();
    

    Remember api’s routes specifys methods alowed(GET, POST, PUT, PATCH, DELETE);

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search