Why isn't MIME content being returned from Microsoft Graph API call?

Viewed 43

I am making this Microsoft Graph API call using PHP to get the MIME content of an email, but I'm not actually seeing any MIME content returned:

$graph = new Graph();

$graph->setAccessToken($accessToken);

try {
    return $graph->createRequest("GET", '/users/' . $emailAddress . '/messages/' . $messageId . '/$value')->execute();

} catch (\Exception $e) {
    print $e->getMessage();
}

What gets returned is this:

[_body:Microsoft\Graph\Http\GraphResponse:private] => GuzzleHttp\Psr7\Stream Object
        (
            ...    
        )

    [_decodedBody:Microsoft\Graph\Http\GraphResponse:private] => Array
        (
        )

    [_headers:Microsoft\Graph\Http\GraphResponse:private] => Array
        (
            ...headers (no mime content)...

    )

[_httpStatusCode:Microsoft\Graph\Http\GraphResponse:private] => 200
[_request] => [[[data about the request]]]

What am I doing wrong? Why isn't it returning the MIME content of the message?

1 Answers

The problem was that the SDK I'm using didn't like something about having $value appended to the end of the request (I suppose because the dollar sign has special meaning in PHP). I found a workaround, which was to use cURL to make the request for the MIME content...

 $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://graph.microsoft.com/v1.0/users/' . $emailAddress . '/messages/' . $messageId . '/$value',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => array(
            'Authorization: Bearer ' . $accessToken
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);
    echo $response;
Related