0
votes

I've been trying to import all contacts from Outlook 365 into another Database. I have no issue getting all the names, emails, addresses, etc.

But when I want to get the Notes that are located on the second page of contacts in Outlook 365 they come out empty.

I'm using PHP code, calling the API with this URL:

https://outlook.office.com/api/v2.0/Me/Contacts 

with no particular parameters. All the login, tokens, etc. part is taken care of and functioning properly.

Here is an example of the array that I receive currently from my call with print_r :

Array ( [Id] => ... [CreatedDateTime] => ... [LastModifiedDateTime] => ... [ChangeKey] => ... [Categories] => Array ( [0] => ... ) [ParentFolderId] => ... [Birthday] => [FileAs] => ... [DisplayName] => ... [GivenName] => ...[Initials] => [MiddleName] => [NickName] => ... [Surname] => ... [Title] => [YomiGivenName] => [YomiSurname] => [YomiCompanyName] => [Generation] => [EmailAddresses] => Array ( [0] => Array ( [Name] => ...[Address] => ...) ) [ImAddresses] => Array ( ) [JobTitle] => ... [CompanyName] => ... [Department] => [OfficeLocation] => ...[Profession] => [BusinessHomePage] => ... [AssistantName] => [Manager] => [HomePhones] => Array ( ) [MobilePhone1] => ... [BusinessPhones] => Array ( [0] => ... ) [HomeAddress] => Array ( ) [BusinessAddress] => Array ( [Street] => ... [City] => ...[State] => ...[CountryOrRegion] => ...[PostalCode] => ...) [OtherAddress] => Array ( ) [SpouseName] => [PersonalNotes] => [Children] => Array ( ) )

`PersonalNotes' are empty every time, even though the Notes in the Contacts contain plenty of text.

The function making the API Call is this one:

public function makeApiCall($method, $url, $payload = NULL) {
  // Generate the list of headers to always send.
  $headers = array(
    "User-Agent: outlook/1.0",         // Sending a User-Agent header is a best practice.
    "Authorization: Bearer ".$this->access_token, // Always need our auth token!
    "Accept: text/*, application/xml, application/json; odata.metadata=none",             // Always accept JSON response.
    "client-request-id: ".self::makeGuid(), // Stamp each new request with a new GUID.
    "return-client-request-id: true",       // Tell the server to include our request-id GUID in the response.
    "X-AnchorMailbox: ".$this->user_email         // Provider user's email to optimize routing of API call
  );
  // print_r($headers);
  $curl = curl_init();

  switch(strtoupper($method)) {
    case "GET":
      error_log("Doing GET");
      break;
    case "POST": // PAYLOAD POUR POST DOIT ETRE json_encode!!!
      error_log("Doing POST");
      $headers[] = "Content-Type: application/json";
      curl_setopt($curl, CURLOPT_POST, true);
      curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
      break;
    case "PATCH":
      error_log("Doing PATCH");
      $headers[] = "Content-Type: application/json";
      curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
      curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
      break;
    case "DELETE":
      error_log("Doing DELETE");
      curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
      break;
    default:
      error_log("INVALID METHOD: ".$method);
      exit;
  }

  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  $response = curl_exec($curl);
  error_log("curl_exec done.");

    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ($httpCode >= 400) {
    return array('errorNumber' => $httpCode,
                 'error' => 'Request returned HTTP error '.$httpCode);
  }

  $curl_errno = curl_errno($curl);
  $curl_err = curl_error($curl);

  if ($curl_errno) {
    $msg = $curl_errno.": ".$curl_err;
    error_log("CURL returned an error: ".$msg);
    curl_close($curl);
    return array('errorNumber' => $curl_errno,
                 'error' => $msg);
  }
  else {
    error_log("Response: ".$response);
    curl_close($curl);
    return json_decode($response, true);
  }
}

Any help would be greatly appreciated, thanks!

1

1 Answers

0
votes

Interesting. I see this too, but only if I set the note in desktop Outlook. If I set it in Outlook Web App, it works fine. I can even go edit the 'broken' one in OWA and it fixes it.

So as a temporary answer, you can edit the contacts in OWA to fix them. I'll update this answer once I have a better answer.