Hi, i m trying to use the web service of the crm on a form.But it's returning this error
XMLHttpRequest cannot load x.api.crm4.dynamics.com/.../accounts.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://x.crm4.dynamics.com' is therefore not allowed access. The response had HTTP status code 401.
On crm documentation say that is not necessary nothing because OAuth.BTW i 'm assign with admin credentials and if a put the path into url is show data.
function GetExistingNIF(nifValue) { var Paramet = "accounts"; //modificar para o link do crm de produção ->Settings > Customizações > link do service root url var clientURL = "x.api.crm4.dynamics.com"; var req = new XMLHttpRequest() req.open("POST", encodeURI(clientURL + "/api/data/v8.2/" + Paramet), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { debugger; if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 204) { var accountUri = this.getResponseHeader("OData-EntityId"); console.log("Created account with URI: " + accountUri); } else { var error = JSON.parse(this.response).error; console.log(error.message); } } }; req.send(JSON.stringify({ name: "Sample account" })); }
I try use xhr and assign withCredentials to true but still not working.It's any system option need to be enable??
Thanks in advance
*This post is locked for comments
I'm trying to make this call on webresource js on a form.i read this msdn.microsoft.com/.../gg334279.aspx and it's says "When you use JavaScript web resources in Microsoft Dynamics 365 you do not need to authenticate because the web resources are part of the application the user is already authenticated. "
Hi
This is a cross domain issue.
If cross domain, please refer the following thread.
community.dynamics.com/.../668271
If you are using the current url then use:
var clientURL = Xrm.Page.context.getClientUrl();
Hi H0nestly, thanks for reaching out.
This sounds like a CORS (cross origin) issue. That error is occurring because the authentication method does not support CORS.
It looks like you are using the Web API which is the only supported method. The next steps are to authorize "Implicit Flow" on you application or website performing this call to the WEB API. It would depend on how you are handling credentials, are the users logged into your website and authorized to CRM through your Active Directory?
Below is a link which is a good place to start. Let me know how we can help.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156