Announcements
I'm trying to make a get request to on premise web Api through postman and getting 401- Unauthorized error.
Is is related to security role/permission? Which security role is needed to make a call through web Api?
I'm using basic authentication.
The below code is also giving the same error.
private HttpClient getNewHttpClient(string userName,string password,string domainName, string webAPIBaseAddress) { HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential(userName, password, domainName) }); client.BaseAddress = new Uri(webAPIBaseAddress); client.Timeout = new TimeSpan(0, 2, 0); return client; }
HttpRequestMessage request = null;
try { request = new HttpRequestMessage(HttpMethod.Post, “api/data/v8.0/accounts”); //uri to accounts request.Content = new StringContent(content.ToString()); //JObject of the data to be posted. request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(“application/json”); //Send the HttpRequest Task<HttpResponseMessage> response = httpClient.SendAsync(requestMessage); //Wait till the Response Execution is complete response.Wait(); //If the response is Successfully executed then it will return the value true if (response.Result.IsSuccessStatusCode) { } } catch (Exception err) { throw new Exception(err.Message); }
Hi Raki
As ClientId you can use a random guid.
The RedirectUri depends on the purpose. If you are using the client in Postman, then you do not need it. It it used to loopback to the client in the authentication process.
/Christian
Christian Jensen Could you please tell us what should be the client id and and RedirectUrl to run this script?
IFD
Sure. On your ADFS server, run the following PowerShell commands:
Add-AdfsClient -Name "My Custom Application Name" -ClientId e5cf0024-a66a-4f16-85ce-99ba97a24bb2 -RedirectUri http://localhost/SdkSample Grant-AdfsApplicationPermission -ClientRoleIdentifier e5cf0024-a66a-4f16-85ce-99ba97a24bb2 -ServerRoleIdentifier mydomain.crm.dynamics.com
I have used ClientId, ClientRoleIdentifier and RedirectUri from Microsofts example.
ServerRoleIdentifier needs to be the identifier of your relying party trust.
If you need your application to access both internal and external relying party, then set the argument to "-ServerRoleIdentifier https://internal.crm.dynamics.com,https://external.crm.dynamics.com"
You need to modify the arguments, to reflect your environment and application.
Hope this solves your problem.
/Christian
Thanks Christian. Can you please share the link to register ADFS client?
Hi
You need to use OAuth.
Microsoft has an example here: Connect to Microsoft Dynamics 365 web services using OAuth
Remember to register the ADFS client. Otherwise your application will fail to connect.
/Christian
It is IFD. Does basic authentication work with IFD? I believe I need to use OAuth2.
Have you enabled Internet-Facing deployment or Claims-Based Authentication?
Hi Christian,
I'm using correct version in the URL. Based on error description it seems that it is a permission issue.
Hi
Is your instance running version 8.0? Or have you updated to 8.1 or 8.2? Because then you nede to correct the version in the url.
/Christian
André Arnaud de Cal...
294,110
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator