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)

HTTP requests to On-Premise Web API

(0) ShareShare
ReportReport
Posted on by

Hello,

I've seen a number of questions posted about how to execute Web API requests via HTTP external to the CRM, but I still am very unclear how to do this. It's rather frustrating that I can simply navigate to the ".../api/data/v8.0/" end point in my browser, but can't seem to access this via any other method. In PowerShell, I've tried the following code:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", 'application/json')
$headers.Add("OData-MaxVersion", '4.0')
$headers.Add("OData-Version", '4.0')

Invoke-WebRequest -Uri 'crmtest.regent.edu/.../v8.0' -Headers $headers -Credential Get-Credential

But I get this error:

Invoke-WebRequest : The underlying connection was closed: An unexpected error 
occurred on a send.
At line:6 char:1
+ Invoke-WebRequest -Uri 
'crmtest.regent.edu/.../v8.0 ...
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpW 
   ebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell 
   .Commands.InvokeWebRequestCommand


I've tried the Invoke-RestMethod as well. Similar requests in JavaScript don't seem to yield requests either.

What am I doing wrong?

Many thanks,

Daniel Hines

Regent University

Christian Leadership to Change the World

*This post is locked for comments

I have the same question (0)
  • joman Profile Picture
    617 on at

    First of all, check your URL in CRM -> Parameters -> Settings -> Resources for developers.

    Then check this: msdn.microsoft.com/.../gg334279.aspx

  • Gopalan Bhuvanesh Profile Picture
    11,401 on at

    Hi

    This (Invoke-WebRequest -Uri 'crmtest....) should work.

    Please check the URL (Example: crmtest.regent.edu/.../accounts) in the browser.

  • Community Member Profile Picture
    on at

    Thank you both for the responses. I was able to working in Powershell; however, I haven't been able to do so in Javascript.

    $(function () {
      $.ajax
        ({
          type: "GET",
          url: "rctrdevcrm.regent.edu/.../v8.0",
          dataType: 'json',
          async: false,
          headers: {
            "Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
          },
          success: function (res) {
            console.dir(res);
          },
        }).fail(function (e) {
          console.dir(e);
         })
    });

    Here's the error I'm getting: 


    XMLHttpRequest cannot load rctrdevcrm.regent.edu/.../v8.0. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access.

    Why can I navigate straight to the page in the browser, or access the data with PowerShell, Power BI, etc., but not via XMLHttpRequest?

    Thanks in advance,

    Daniel Hines

  • Suggested answer
    joman Profile Picture
    617 on at

    Good day. You make cross-domain request, so browser don't do it.

    You need to make a server, witch you are sending a request, give you a cookie, that allow cross-domain requests.

    More info:

    developer.mozilla.org/.../Access_control_CORS

    or google: Access-Control-Allow-Origin

  • Community Member Profile Picture
    on at

    Thank you for the links. Is this something I can configure on an on-premise instance of Dynamics CRM 2016 (not IFD)?

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