Search code examples
microsoft-graph-apioffice365api

Getting the default contact Folder


I'm using trying to get default contacts folder. currently I'm trying testing them on graph api. if I https://graph.microsoft.com/v1.0/me/contacts, I can get all the contacts list correctly. For example,

"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('8fa9xxxx-4eb9-acb4xxxxx5707')/contacts",
"value": [
    {
        "@odata.etag": "W/\"EQAAAB........HYPlAACRIrzX\"",
        "id": "AAMkAGUyM2Exxxxxxxxxxxxxxxxxxxxxxxx.... xxQVwWHYPlAACRUWbVAAA=",
        "createdDateTime": "2024-04-15T01:39:57Z",
        "lastModifiedDateTime": "2024-04-15T01:39:59Z",
        "changeKey": "EQAAA.......YPlAACRIrzX",
        "categories": [],
        "parentFolderId": "AAMkAGUyM2xxxxxxxxxAAAAAEOAAA=",
        "birthday": null,
        "fileAs": "gisu123"..........
.......,

However, If I do https://graph.microsoft.com/v1.0/me/contactFolders there is no return.

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('8fxxxxxxxxxxxx5707')/contactFolders",
    "value": []
}

But it works, when I use parentfolder id with contactfolders.

https://graph.microsoft.com/v1.0/me/contactfolders/AAMkAGUxxxxxxxxxI3Ny1iMDUyLWI0OTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXBZC4AAAAAAEOAAA=
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('8fa9a94f-1752-4eb9-acb4-a2eac51a5707')/contactFolders/$entity",
    "id": "AAMkAGUyM2xxxxxxxxxxxxxxxxxxAQDMA-lWCJwxSZ24LJrXBZCxxxxxOAAA=",
    "parentFolderId": "AAMkAGUyM2ExYxxxxxxx3Ny1iMDUyLWI0OTIyNzAyODVhMwAuAAAAxxxxxxxWkPkKe6D2sAQDMA-lWCJwxSZ24LJxxxxxAAAAAEIAAA=",
    "displayName": "Contacts"
}

However, this method is only possible when there is existing address on contacts. Is there way to get Contacts (default folder) directly?


Solution

  • It should be possible by using well-known name Contacts for default folder.

    GET https://graph.microsoft.com/v1.0/me/contactFolders/contacts