Never mind! Solved it by myself 👍
Calling Azure pricing api from Azure App Service (Web App) not working.
Hi,
My task is to fetch the pricing related details by using the "https://prices.azure.com/api/retail/prices" url of azure. I am using C# web api to get the pricing details for any azure service (say for example windows VM price).
public async Task<IActionResult> GetWindowsVmPrice(string currencyCode, string region, string size)
{
string pricingBaseUrl = "https://prices.azure.com/api/retail/prices";
string requestUrl = $"{pricingBaseUrl}?currencyCode='{currencyCode.ToUpper()}'&$filter=serviceName eq 'Virtual Machines' " +
$"and armRegionName eq '{region}' and armSkuName eq '{size}' and type eq 'Consumption' " +
$"and (skuName eq '{sName.Trim()}' or skuName eq '{size}') and contains(productName, 'Windows')";
using HttpClient client = new HttpClient();
var response = await client.GetAsync(requestUrl);
string content = await response.Content.ReadAsStringAsync();
var results = JsonConvert.DeserializeObject<JObject>(content);
return Ok(results);
}
The code is working fine and I am getting the expected result when running it localhost swagger. Now the problem starts when I host this service in Azure App Service. The swagger there giving the result as 200 OK but with an empty [] json.
So, what is the problem in Azure when the same code is running fine in localhost.
Please advise if I am missing anything. Do I need to enable something in Azure or in the code or else. I am lost here as there is no error. Thanks.