Calling Azure pricing api from Azure App Service (Web App) not working.

Atanu Gupta 141 Reputation points
2023-08-30T12:26:52.9866667+00:00

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.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,685 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Atanu Gupta 141 Reputation points
    2023-08-31T06:05:07.4333333+00:00

    Never mind! Solved it by myself 👍


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.