Azure API Management
How to create API using Azure API Management REST API in C#
Can Anyone suggest me for creating API that uses Azure API Management REST API in C#. I Tried but not able to call create an API Thanks in Advance private static async Task<string> CreateApiTask(string apiId) { string requestUrl = string.Format("{0}/apis/{1}?api-version={2}", baseUrl, Guid.NewGuid(), apiVersion); using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var request = new HttpRequestMessage(HttpMethod.Put, requestUrl); request.Headers.Authorization = new AuthenticationHeaderValue( "SharedAccessSignature", sharedAccessSignature); // var model = new RequestBody(); string str = JsonConvert.SerializeObject(new RequestBody()); equest.Content = new StringContent(str, Encoding.UTF8, "application/json"); HttpResponseMessage response = await httpClient.PutAsync(requestUrl, request.Content); //// (requestUrl, model); string responseBody = await response.Content.ReadAsStringAsync(); return responseBody; } } Error: {StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Date: Wed, 19 Aug 2015 07:19:34 GMT WWW-Authenticate: SharedAccessSignature realm="" Content-Length: 0 }}
Hi, It looks like you are using an invalid SAS in the header.
Hi, You need to set the header name as Authorization, See https://msdn.microsoft.com/en-us/library/azure/dn776326.aspx i.e. for instance // Define the required headers to specify the API version and operation type. request.Method = "GET"; request.Headers.Add("Authorization", sharedAccessSignature); Header name SharedAccessSignature only works for resources like apis. Kind Regards, Steef-Jan Wiggers (Microsoft Azure MVP)BizTalk
Hello swapnil, I am not sure about this but I have doubt in SharedAccessSignature basic authentication. I suggest you to cross check credentials passed to shared Access Signature. In the meanwhile I am researching more with regards to your request and I will get back to you with update. Thank you for understanding. Regards, Sunil.HP
Hi, It looks like you are using an invalid SAS in the header.
Hi, You need to set the header name as Authorization, See https://msdn.microsoft.com/en-us/library/azure/dn776326.aspx i.e. for instance // Define the required headers to specify the API version and operation type. request.Method = "GET"; request.Headers.Add("Authorization", sharedAccessSignature); Header name SharedAccessSignature only works for resources like apis. Kind Regards, Steef-Jan Wiggers (Microsoft Azure MVP)BizTalk
Related Links
Set a variable with JWT claim as value
Creating a Webservice in Azure
REST Api just heavily changed?
Azure Resource created by/ created at
Developer portal showing various Liquid errors
Is there REST API to Create/Update/Delete API Policies?
Azure Service Fabric Cluster with OWIN Stateless Web api.
eLogic Learning LMS - Configuring the Multi-Language feature with Azure Cognitive Services
APIM instance stuck on "updating" state after upgrading licens
401 error
Mutual Certificate Proxy Authentication
Call Azure Api from website
Azure API Throttling.
API management on Azure Stack?
Developer portal no longer supplying Authorisation code when OAuth2 provider required
Cannot find the authorization header when uses Basic authentication for backend service