Chetan
Chetan

Reputation: 226

Error while getting Contacts from Microsoft graph api

I am trying to fetch a user's Contacts using the Microsoft Graph SDK. I am able to get the user details using graphClient.me(), but when I try to get a list of contacts I am getting an error:

Graph SDK ERROR : 
  Error from data task : 
    Error Domain=com.microsoft.graph.errors 
    Code=400 "bad request" 
    UserInfo={
      NSLocalizedDescription=bad request, 
      error= AuthenticationError : Error authenticating with resource
    }

Graph SDK ERROR : Caused by request <NSMutableURLRequest: 0x1738bc70> { 
  URL: https://graph.microsoft.com/v1.0/me/contacts 
}

My Code:

self.graphClient.me().contacts().request().getWithCompletion {
  (_ contacts: MSCollection?,
   _ nextRequest: MSGraphUserContactsCollectionRequest?,
   _ error: Error?) in

    if error == nil {
        print("contacts \(contacts)")
    }
    else {
        print("error \(error?.localizedDescription)")
    }
}

My Scopes:

let SCOPES   = ["openid", "profile","User.Read","Contacts.Read"]

Upvotes: 1

Views: 491

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

The /contacts endpoint requires that the user has an accessible Exchange Mailbox. If the user doesn't have a mailbox provisioned in Exchange Online for this tenant, several endpoints that rely on Exchange will fail (/contacts, /events, /messages, etc.).

Upvotes: 1

Related Questions