3
votes

Executed the PHP quickstart code for outlook restapi v2.0 for accessing mails with oauth2 authorization.

Complete Code can be viewed here - "https://dev.outlook.com/RestGettingStarted/Tutorial/php" under "outlook.php"

scope: https://outlook.office.com/mail.read
token_type: Bearer
I've received the access_token, expires_in, id_token and id_token_expires_in
and expires_in value is 3600

public static function getMessages($access_token, $user_email) {
  $getMessagesParameters = array (
    // Only return Subject, ReceivedDateTime, and From fields
    "\$select" => "Subject,ReceivedDateTime,From",
    // Sort by ReceivedDateTime, newest first
    "\$orderby" => "ReceivedDateTime DESC",
    // Return at most 10 results
    "\$top" => "10"
  );
...

Is there any changes need to be done on the "$getMessagesParameters"? I tried removing everything but still it didn't work!(gives a 400 HTTP error)

Is there any recent modifications in the way we access outlook rest api resources?

update: I used a hotmail account to create a application and used the same account for accessing mails from. Is it because mails with hotmail.com is not completely integrated with outlook.com mail services?

Now the Error code changed to "404"

Checked it in Outlook Sandbox and they state that the user inbox should be REST API enabled for it to work.

this is not a duplicate of "Office 365 API - Request returned HTTP error 400"(where the questioner has troubles with contacts and calendars but not mails)

1

1 Answers

0
votes

So you're saying you get an error in the sandbox? If you're getting the error that your mailbox is not enabled for the REST API, then that's the cause of the issue. Outlook.com accounts (Hotmail.com included) are being enabled in waves, and yours hasn't been enabled yet. At this time there's no way to enable them on demand, so for that mailbox you would just have to wait.

If you want to test right away, you can create a new Outlook.com account in North America, and it should be enabled for the APIs right away.