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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting all related Contact for an Account entity in Dynamics 365 CRM v9.0 web api

(0) ShareShare
ReportReport
Posted on by 154

I've read a few questions regarding this and the proposed solutions don't fit with what I am seeing in the CRM web API. At any rate...

Basically, I'm querying the D365 web API and I'm trying to get all of the related contacts for an account.

Been following this link:

docs.microsoft.com/.../query-data-web-api

Trying to use $expand but it only will bring over _primarycontactid_value. So just the one primary contact and not everyone that is related to the Account.

It would look something like the following:

/api/data/v9.0/accounts&?select=name&$expand=Contacts(fullname, email)

The only fields in Account that have "contact" in them are:

preferredcontactmethodcode
_primarycontactid_value
address2_primarycontactname
address1_primarycontactname
_tcc_primaryinvoicecontactid_value
_tcc_consultingcontact_value
_tcc_contactlist_value //some custom field that doesn't apparently do anything
_new_foundationcontact_value
_tcc_primaryapcontactid_value

So none of which can be used to look-up all of the contacts... that I know of.

Another way to do it would be to start with the Contact first and then $expand= on the _parentcustomerid_value. But I need to filter on the Account to specify certain accounts that I want... this would just bring over every account and be incredibly slow. I'm not sure there is a way to $filter= on an $expand= value.

So:

1. How can I query the Account and all the related to Contacts for an Account?
2. If there is no way, is it possible to use $filter= on and $expand= value?

Trying to keep the amount of queries to a minimum. This could be solved by doing multiple iterative queries, but that will just make it incredibly slow. Or just query everything and piece it together, but that will be slow as well.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ishraqiyun77 Profile Picture
    154 on at

    Ok, stumbled across the answer: contact_customer_accounts.

    Query ends up looking like the following: 

    /api/data/v9.0/accounts&?select=name&$expand=contact_customer_accounts($select=fullname).

    Still takes a little while to generate, but works.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans