Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

querying data using web api

(0) ShareShare
ReportReport
Posted on by

Hi all,

When querying data using web api,not able to retrieve the data.When i debugged "readystate" is 1 but it should be 4 What is the issue and do i need to add any code?

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: querying data using web api

    Hi ,

    Please  try  to copy the code which I have shared   ? its should be without ().

    see there is a difference code  - 

    Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts()

    Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts? 
  • Community Member Profile Picture
    on at
    RE: querying data using web api

    its not working with changing the version also

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: querying data using web api

    Hello ,

    Try with changing the version , if you have v9.0 it will also work with v8.2 .

          function Practice()
          {
              var req = new XMLHttpRequest();
              req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?$select=address1_city,name&$filter=address1_city eq 'Sydney'", 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 address1_city = results.value[i]["address1_city"];
                              var name = results.value[i]["name"];
                          }
                      } else {
                          Xrm.Utility.alertDialog(this.statusText);
                      }
                  }
              };
              req.send();
          }


  • Community Member Profile Picture
    on at
    RE: querying data using web api

    yea justin, am able to get in the browser...I tested

  • Justinjose Profile Picture
    2,707 on at
    RE: querying data using web api

    Hi tejagupta,

    are you able to get the result in browser? can you try this on browser. 

    https://xxxxxx.crm4.dynamics.com/api/data/v9.0/accounts()?$select=address1_city,name&$filter=address1_city eq 'redmond'

    Thanks

    Justin Jose

  • Community Member Profile Picture
    on at
    RE: querying data using web api

    Hi aric,thanks for your reply.Below is the code.am calling function onchange of a field.

    function Practice()

    {

    var req = new XMLHttpRequest(); //req object

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts()?$select=address1_city,name&$filter=address1_city eq 'redmond'", false); //query

    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 result = JSON.parse(this.response);

    alert(result.length);

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

    {

    var name = result.value[i]["name"];

    alert(name);

    }

           }

    else

    {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    }

  • Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: querying data using web api

    Can you please share what you are trying to do? Code if possible?

    What version of Dynamics CRM are you on (8.x, 9.0), and how did you create the WebApi calls?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans