API management URL is giving Missing subscription key Issue API management URL is giving Missing subscription key Issue azure azure

API management URL is giving Missing subscription key Issue


If you enable the option to Require subscription for the product settings, then you must pass the below header Ocp-Apim-Subscription-Key.Even you provide subscription key, the key should belong to the product which the API includes.If you don't want the subsciption option, disable it in the product settings.


If you enable the option to Require subscription for the product settings, then you must pass the below header Ocp-Apim-Subscription-Key. Even you provide subscription key, the key should belong to the product which the API includes. Add the your APIs in your products.

  1. Select the Products menu/link from Azure portal.
  2. Select the product from list.
  3. Select the APIs from selected product options.
  4. Click on Add button and select your API from list and click on Select.

You are good to use your API using Postman or your code.You have to pass the subscription key in header key (Ocp-Apim-Subscription-Key).

You can find the subscription key (Primary/Secondary) in api developer portal on profile screen.


You have to pass your subscription key in request headers.

Add this to your C# code

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);request.Headers.Add("Authorization", BearerToken); request.Headers.Add("Ocp-Apim-Subscription-Key", config["OcpApimSubscriptionKey"]);

Add this to your app settings file

"OcpApimSubscriptionKey": "your key",

Sample code:

 try            {                using (HttpClient client = new HttpClient())                {                    client.BaseAddress = new Uri(url);                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));                    client.DefaultRequestHeaders.Add("Authorization", BearerToken);                    client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", config["OcpApimSubscriptionKey"]);                    HttpResponseMessage response = client.GetAsync(url).Result;                    if (response.IsSuccessStatusCode)                    {                        return response.Content.ReadAsStringAsync().Result;                    }                    else                    {                        var ResponseResult = await response.Content.ReadAsStringAsync();                        return ResponseResult;                    }                }            }            catch (WebException ex)            {                WebResponse errorResponse = ex.Response;                using (Stream responseStream = errorResponse.GetResponseStream())                {                    StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));                    string errorText = reader.ReadToEnd();                }                throw;            }            catch (ArgumentNullException ex)            {                throw;            }            catch (InvalidOperationException ex)            {                throw;            }            catch (HttpRequestException ex)            {                throw;            }