Hello,
This is the first time I'm using the new (to me) Web API. According to the documentation, running it from a web resource doesn't require authentication. Here's my function that I attached to an onChange event of a text field (just for testing purposes).
https://msdn.microsoft.com/en-us/library/mt595798.aspx
When you use the Web API with JavaScript within HTML web resources, form scripts, or ribbon commands you don’t need to include any code for authentication. In each of these cases the user is already authenticated by the application and authentication is managed by the application.
(I used v8.1 because that's what the Developer Resources page says vs what the docs say: v8.2. Anyway both give the same result.)
(Also, this editor is clobbering the URL. /.../ should say /api/data/v8.1/.)
function getDataWebApi() { var uri = "xxx.crm.dynamics.com/.../accounts" var options = [ "$select=name", "$top=3" ]; var fullUri = uri + "?" + options.join("&"); var request = new Request(fullUri, { method: "get" , mode: "cors" , headers: { "Accept": "application/json", "OData-MaxVersion": "4.0", "OData-Version": "4.0" } }); fetch(request).then(function (response) { console.log(response); return response; }); }
Below is what I see in the Chrome console:
Response {type: "basic", url: "xxx.crm.dynamics.com/.../accounts$select=name&$top=3", redirected: false, status: 401, ok: false…} body: ReadableStream bodyUsed: false headers: Headers ok: false redirected: false status: 401 statusText: "Unauthorized" type: "basic" url: "xxx.crm.dynamics.com/.../accounts$select=name&$top=3" __proto__: Response
Anyone know what I'm doing wrong?
*This post is locked for comments