web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Odata return nested level of entity(account)

(0) ShareShare
ReportReport
Posted on by 355

hi,i trying  to get all accounts records by odata endpoint with list all contacts ,in order to do this,used below url in my post man:

https://crm-preview.***/main/api/data/v9.0/accounts/contact_customer_accounts?$select=firstname

and my response 

"@odata.context": "https://crm-preview****/main/api/data/v9.0/$metadata#accounts(name,contact_customer_accounts(firstname))",
    "value": [
        {
            "@odata.etag": "W/\"2922751\"",
            "name": "Hockey Federation",
            "accountid": "46ef24d1-a0c1-e911-b42a-005056a8646b",
            "contact_customer_accounts": [],
            "contact_customer_accounts@odata.nextLink": "https://crm-preview.***/main/api/data/v9.0/accounts(46ef24d1-a0c1-e911-b42a-005056a8646b)/contact_customer_accounts?$select=firstname"
        },
        {
            "@odata.etag": "W/\"2181982\"",
            "name": "Corporate Club",
            "accountid": "a0e0aef4-04c8-e911-b42a-005056a8646b",
            "contact_customer_accounts": [],
            "contact_customer_accounts@odata.nextLink": "https://crm-preview.***/main/api/data/v9.0/accounts(a0e0aef4-04c8-e911-b42a-005056a8646b)/contact_customer_accounts?$select=firstname"
        },

as you can see , contact_customer_accounts is empty array.

if i put ID in my accounts everything worked but i want to get all my accounts records with details of contacts.

I have the same question (0)
  • Suggested answer
    Bhartendu B Pandey Profile Picture
    Microsoft Employee on at

    Hello Farbodkain,

     

    Thank you for writing to us. I see we are trying to get details of all contacts related to all accounts. I tried quickly checking through and the same may be possible as per the use of the below link

    Retrieve related entity records by expanding single-valued navigation properties.

    https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/retrieve-related-entities-query

     

    Also sometimes we may want to construct the query to retrieve the records in dynamics CRM . This can be done by using the Advanced find and then getting the fetchXML . Once you get the fetch XML you can use the restbuilder to construct Odata queries .

     

    Please feel free to browse through the below links in the community article

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/305214/odata-query

     

    Please mark my answer as verified if you found it helpful. Please let me know if you have any other questions around the above.

    Bhartendu Pandey

    Support Engineer - Customer Engagement- Dynamics CRM/PowerApps/Power Automate

    Microsoft

  • farbodkain Profile Picture
    355 on at

    @Bhartendu Pandey

    thanks , i checked and only different found out is url which use "api/data/v9.1" version 9.1 and  im using version 9.0. i don't know how can upgrade my crm odata to better version. if you have any suggestion to give me a clue ,really appreciated to share with me.

    and about second link fetchXML , im working on it. i don't know anything about it.

  • Suggested answer
    Bhartendu B Pandey Profile Picture
    Microsoft Employee on at

    Hello Farbodkain,

    There is no way to update Odata version number as such. It is expected that the Odata call should reflect the same version number of the CRM server. 

    I had a trial organization set up with Sample data and I was able to get the results for all accounts with related contacts . 

    below is the exact URL i used .. https://[orgurl]/api/data/v9.1/accounts?$select=name&$expand=primarycontactid($select=contactid,fullname).



    pastedimage1589777716913v2.png

    Can you try using the exact same URL and see if you are able to retrieve the results?

    Please mark my answer as verified if you found it helpful. Please let me know if you have any other questions around the above.

     

    Bhartendu Pandey

    Support Engineer - Customer Engagement- Dynamics CRM/PowerApps/Power Automate

    Microsoft

  • farbodkain Profile Picture
    355 on at

    thanks, but i need all contact related to one account .this query only return primary contact.

  • Bhartendu B Pandey Profile Picture
    Microsoft Employee on at

    Hello Farbodkain ,

    I am afraid I do not have a direct way of achieving this . I will leave this thread open for anyone to asisst. If I do find ways to achieve this I will update on it .

     

    Bhartendu Pandey

    Support Engineer - Customer Engagement- Dynamics CRM/PowerApps/Power Automate

    Microsoft

  • Suggested answer
    Chintan Patel Profile Picture
    100 on at

    Hello Farbodkain,

    I guess this should help.

    https://[CRM_URL]/api/data/v9.1/accounts?$top=5&$select=accountid&$expand=contact_customer_accounts($select=contactid)

    {
    "@odata.context":"[CRM_URL]/api/data/v9.1/$metadata#accounts(accountid,contact_customer_accounts(lastname))",
    "value":[
    {
    "@odata.etag":"W/\"20120024\"",
    "accountid":"5e505212-fdeb-e811-a96e-000d3a30d104",
    "contact_customer_accounts":[
    {
    "@odata.etag":"W/\"42719331\"",
    "lastname":"Patel",
    "_parentcustomerid_value":"5e505212-fdeb-e811-a96e-000d3a30d104",
    "contactid":"85589fca-982d-e811-a950-000d3a30d7c8"
    },
    {
    "@odata.etag":"W/\"20302661\"",
    "lastname":"sdfds",
    "_parentcustomerid_value":"5e505212-fdeb-e811-a96e-000d3a30d104",
    "contactid":"2f7c5e10-fdeb-e811-a971-000d3a30d7c8"
    }
    ],
    "contact_customer_accounts@odata.nextLink":"[CRM_URL]/api/data/v9.1/accounts(5e505212-fdeb-e811-a96e-000d3a30d104)/contact_customer_accounts?$select=lastname"
    },
    {
    "@odata.etag":"W/\"20120016\"",
    "accountid":"de46dea5-f7eb-e811-a971-000d3a30d7c8",
    "contact_customer_accounts":[
    {
    "@odata.etag":"W/\"20302665\"",
    "lastname":"Payal",
    "_parentcustomerid_value":"de46dea5-f7eb-e811-a971-000d3a30d7c8",
    "contactid":"137573ab-f7eb-e811-a977-000d3a30dc28"
    }
    ],
    "contact_customer_accounts@odata.nextLink":"[CRM_URL]/api/data/v9.1/accounts(de46dea5-f7eb-e811-a971-000d3a30d7c8)/contact_customer_accounts?$select=lastname"
    },
    {
    "@odata.etag":"W/\"14540944\"",
    "accountid":"0de7b55a-aa68-e811-a95c-000d3a30da4f",
    "contact_customer_accounts":[
    {
    "@odata.etag":"W/\"27676910\"",
    "lastname":"Neel",
    "_parentcustomerid_value":"0de7b55a-aa68-e811-a95c-000d3a30da4f",
    "contactid":"9fe89072-a8c0-e811-a969-000d3a30da4f"
    }
    ],
    "contact_customer_accounts@odata.nextLink":"[CRM_URL]/api/data/v9.1/accounts(0de7b55a-aa68-e811-a95c-000d3a30da4f)/contact_customer_accounts?$select=lastname"
    },
    {
    "@odata.etag":"W/\"27675357\"",
    "accountid":"958bd9e4-f2d1-e811-a969-000d3a30da4f",
    "contact_customer_accounts":[
    {
    "@odata.etag":"W/\"27675358\"",
    "lastname":"Contact",
    "_parentcustomerid_value":"958bd9e4-f2d1-e811-a969-000d3a30da4f",
    "contactid":"6ad2cf39-f3d1-e811-a969-000d3a30da4f"
    }
    ],
    "contact_customer_accounts@odata.nextLink":"[CRM_URL]/api/data/v9.1/accounts(958bd9e4-f2d1-e811-a969-000d3a30da4f)/contact_customer_accounts?$select=lastname"
    },
    {
    "@odata.etag":"W/\"21984066\"",
    "accountid":"0c2af21a-daeb-e811-a96a-000d3a30da4f",
    "contact_customer_accounts":[
    {
    "@odata.etag":"W/\"21984067\"",
    "lastname":"Migration Contact Name",
    "_parentcustomerid_value":"0c2af21a-daeb-e811-a96a-000d3a30da4f",
    "contactid":"ea4e7526-daeb-e811-a977-000d3a30dc28"
    }
    ],
    "contact_customer_accounts@odata.nextLink":"[CRM_URL]/api/data/v9.1/accounts(0c2af21a-daeb-e811-a96a-000d3a30da4f)/contact_customer_accounts?$select=lastname"
    }
    ]
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 79 Super User 2026 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 58 Most Valuable Professional

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 42 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans