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)

Web API returning 400 Bad Request

(0) ShareShare
ReportReport
Posted on by 605

Hi All,

I am using Microsoft Dynamics 2016 Online.

I am have a HTML in which I have a javascript which calls a CRM WEB API and filters w.r.t fullname. Here is my code

var searchBoxSelectedValue = window.parent.Xrm.Page.getAttribute("new_name").getValue();

var req = new XMLHttpRequest();

req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/contacts?$select=fullname&$filter=fullname eq" + searchBoxSelectedValue, false);
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.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 mydata = results.value[i]["fullname"];
}
} else {
alert(this.statusText);
}
}
};

req.send(); // error shown in this line

I am getting an error saying "Bad Request" 400. 

req.onreadystatechange = function() {} does not get executed, it gets skipped.

thanks in advance.

Regards,

Rahul

*This post is locked for comments

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

    I think your URL is not correct. Please check below things:

    1. window.parent.Xrm.Page.context.getClientUrl()  if this is returning the CRM URL.

    2. v9.0 is the correct api version for your environment.

    3. Please give a space between eq and ".

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    you can double check your query with the CRMRestBuilder: github.com/.../CRMRESTBuilder

  • Rahul G J Profile Picture
    605 on at

    I tried in CRM rest builder, in there inside code editor i created a variable and tried. Still giving me bad request.

  • Mahendar Pal Profile Picture
    45,095 on at

    Have you tried to debug your code and check if query is forming well ?? you can debug js by writing debugger only, check your query while debugging what's is comming or share it here.

    Thanks

  • Verified answer
    Rahul G J Profile Picture
    605 on at

    Hi All,

    I got this problem solved i was erring with single quotes. here is my corrected line:

    req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/contacts?$select=fullname&$filter=fullname eq " + "'"+ searchBoxSelectedValue + "'", false);

    Regards,

    Rahul

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