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)

Issue with HTTP WEB API Request

(0) ShareShare
ReportReport
Posted on by 6,211

Hi All,

I want to get all the account related opportunities data with the web api call in dynamics crm.

i am getting all the account list with this web api call "https://testcrm9.api.crm.dynamics.com/api/data/v9.0/accounts" but now i want its related opportunities also. how can i achieve this?

Thanks,

Shahbaaz

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    Pls use the below sample. Am here trying to retrieve related contact from account entity.

    Xrm.WebApi.retrieveRecord("account", "a8a19cdd-88df-e311-b8e5-6c3be5a8b200", "?$select=name&$expand=primarycontactid($select=contactid,fullname)").then(

       function success(result) {

           console.log(`Retrieved values: Name: ${result.name}, Primary Contact ID: ${result.primarycontactid.contactid}, Primary Contact Name: ${result.primarycontactid.fullname}`);

           // perform operations on record retrieval

       },

       function (error) {

           console.log(error.message);

           // handle error conditions

       }

    );

    Hope this helps.If the suggestion resolved your query .Pls mark it as answered/verified to close the thread.

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    Thanks syed for the reply, mobile team is using that web api and they want all the account in a single request with opportunity

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    Thanks syed for the reply, mobile team is using that web api and they want all the account in a single request with opportunity data, for the single record we can use testcrm9.api.crm.dynamics.com/.../opportunity_parent_account it will give account with related opportuntiy

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at

    Hi, 

    by passing the Account Guid id you can get related opportunities. Please see below sample code. I have marked Account Guid in green colour. 

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9/opportunities?$filter=_accountid_value eq 6B40A32D-6F03-E411-889B-D89D6763DF88", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var results = JSON.parse(this.response);
    for (var i = 0; i < results.value.length; i++) {
    var opportunityid = results.value[i]["opportunityid"];
    }
    } else {
    Xrm.Utility.alertDialog(this.statusText);
    }
    }
    };
    req.send();

    please let me know if you have any question

    Thanks

  • Syed Ibrahim Profile Picture
    6,257 on at

    Do you mean all the accounts and it's opportunities in your Organisation by one call?

  • Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Syed,

    Yes, in one call i want to get all account and its related opportunity data.

    Thanks,

    Shahbaaz

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    Simply use batch request to get account data and all related opportunities in single request:

    msdn.microsoft.com/.../mt607719.aspx

  • Syed Ibrahim Profile Picture
    6,257 on at

    Hi shabazz you can use the retrievemultiple method to retrivve account related opportunity. Pls refer the below sample code which gets all the contact info for an account.

    Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3&$expand=primarycontactid($select=contactid,fullname)", 3).then(

       function success(result) {

           for (var i = 0; i < result.entities.length; i++) {

               console.log(result.entities[i]);

           }        

           // perform additional operations on retrieved records

       },

       function (error) {

           console.log(error.message);

           // handle error conditions

       }

    );

    //Refer below for more info.

    docs.microsoft.com/.../retrievemultiplerecords

    Hope this helps. Pls mark it as Answered/Verified to close the thread if suggestion resolved your query

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans