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)

The response had HTTP status code 401

(0) ShareShare
ReportReport
Posted on by 458

Hi all experts.
I want the count  the orders and their details out of the CRM, Via OData.
I have called an OData via simple JS inside HTML file.
I have created the OData URL via Rest Builder solution.
When I go to my URL, It works good and dsiplay me the output,
But when I call it via Ajax, It gives me this :

Failed to load xxxxxxxxxxxxx/.../SalesOrderSet$select=AccountId,Name,OpportunityId,SalesOrderId&$filter=StatusCode/Value%20eq%20100001%20and%20bmsd_OrderType/Value%20ne%20100000001: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 401.

also this :

401 (Unauthorized)


Here is my JS Code : 

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: "xxxxxxxx/.../SalesOrderSet$select=AccountId,Name,OpportunityId,SalesOrderId&$filter=StatusCode/Value%20eq%20100001%20and%20bmsd_OrderType/Value%20ne%20100000001",
    beforeSend: function(XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    async: true,
    success: function(data, textStatus, xhr) {
        var results = data.d.results;
        for (var i = 0; i < results.length; i++) {
            var accountId = results[i].AccountId;
            var name = results[i].Name;
            var opportunityId = results[i].OpportunityId;
            var salesOrderId = results[i].SalesOrderId;
        }
    },
    error: function(xhr, textStatus, errorThrown) {
        alert(textStatus + " " + errorThrown);
    }
});

What I am doing wrong?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Shaminderpal Singh Profile Picture
    1,565 on at

    Hi,

    If you are calling it outside crm , you won't be able to call it directly, it needs to be authenticated first. You can use Oauth to satisfy authentication and generate access token to call web api.

    Refer this article-docs.microsoft.com/.../walkthrough-registering-configuring-simplespa-application-adal-js

    -Shaminder

  • Albert_ Profile Picture
    458 on at

    It works good in IE !

    But You are right, Its because of the Oauth , and is the problem in the Dynamic CRM 2011.

    Thank you, I prefer to make it on the IE in order to solve the Issu ( Skip it ! )

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