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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Odata Query

(0) ShareShare
ReportReport
Posted on by

Hi All,

I'm trying to construct an OData query to retrieve data from Invoice entity. I can retrieve all the header records from Invoice However when I'm trying to query record from the related customer it's throwing me an error 

here is a sample of my query

dynamics.com/api/data/v8.2/invoices(1A0D1E72-2C87-E711-814D-9CDC71557F61)?$select=Name,invoice_customer_accounts.name&$expand=invoice_customer_accounts

I need 2 thing from this query 

1) all the related parent entity values. 

2) all the related child entity values.(eg= line items)

Thanks in advance

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hello Ankur,

    I had a similar issue, which i had to verify the OData Metadata.

    odata.PNG

    For the relationship you require, change the invoice_customer_accounts to customerid_account. I also noted the "Name" property needs to be in lower case, due to the schema name.

    Try the following:

    dynamics.com/api/data/v8.2/invoices(1A0D1E72-2C87-E711-814D-9CDC71557F61)?$select=name&$expand=customerid_account

    Cheers!

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Ankur, 

    Here is the rules to  use expand -

    http://[Organization URI]/api/data/v8.2/invoices(65f77a42-5f0e-e611-80e0-00155da84c03)?$select=invoicename,invoicefield1,invoicefield2&$expand=customerlookupid($select=customerfiledname1,customerfiledname2,customerfiledname3)


    So the rule is you need to replace only lookup id of customer as per your lookup name.

    &$expand = customerid

    For more information please refer -

    https://msdn.microsoft.com/en-us/library/mt770366.aspx 

    Go to section 2 the point 2.

    Sample contact retrieve -

    http://[Organization URI]/api/data/v8.2/accounts(65f77a42-5f0e-e611-80e0-00155da84c03)?$select=name,&$expand=primarycontactid($select=fullname,jobtitle,annualincome)


    Hope this helps to build the query. You should use always logical name.

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    In addition to that , I will suggest you to write your query using Rest builder, which will help, using expend you can get child record with primary entity.  

    you can also refer my samples here: himbap.com/blog

  • Verified answer
    Community Member Profile Picture
    on at

    Thanks for your answers my correct query looks something like this:

    /api/data/v8.2/invoices(1A0D1E72-2C87-E711-814D-9CDC71557F61)?$select=name,invoicenumber,datedelivered,duedate,new_dbms_qbpaid_amount,billto_line1&$expand=customerid_account($select=name)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans