Api Call Fails with 500 despite returning Data

Anonymous
2024-04-04T17:22:51.1533333+00:00

The below code is failing with "the server responded with a status of 500 ()"

But data is being populated in elevation, I am trying to populate the elevation in browser using ajax call

but couldn't succeed.

https://api.open-meteo.com/v1/elevation?latitude=52.52&longitude=13.41

https://open-meteo.com/en/docs/elevation-api

string urlel = $"https://api.open-meteo.com/v1/elevation?latitude={data.latitude}&longitude={data.longitude}";
            var responseel = client.GetAsync(urlel).Result;
            string jsonel = await responseel.Content.ReadAsStringAsync();
            dynamic datael = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonel);
            int elevation = datael.elevation;
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,553 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 64,901 Reputation points
    2024-04-04T19:55:33.46+00:00

    your sample url returns

    {
        "elevation": [
            38.0
        ]
    }
    
    

    so elevation is an array of numbers, not an int. try:

    double elevation = datael.elevation[0];

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.