Api_key missing in request

I am testing the direcctions API in a C# winforms program. If I try the URL in the browser I have a good response with the route, but when I do the same request inside my C# program I always get “Api_key missing in request”.

my code for the request:
var baseAddress = new Uri(“https://api.openrouteservice.org/v2/directions/driving-car?api_key=myAPIKEY&start=8.681495,49.41461&end=8.687872,49.420318”);

        using (var httpClient = new HttpClient { BaseAddress = baseAddress })
            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8");

            using (var response = await httpClient.GetAsync("directions"))
                string responseData = await response.Content.ReadAsStringAsync();

Hi @fvilanova
actually, the example request might not be correct in C# as we can’t test this for each language. This is a autogenerated template.

If you are doing a normal GET request the Uri should be fine like this.
Maybe you have to investigate on how to do a normal GET request in C#.
If you have a working example and you will provide it to us, we can update our template for other C# users :slight_smile:

Best regards, Amandus

Hello Amandus,
With this code works great:

string URL = “https://api.openrouteservice.org/v2/directions/driving-car?api_key=myAPIKEY&start=8.681495,49.41461&end=8.687872,49.420318”;

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
        request.Method = "GET";
        var webResponse = request.GetResponse();
        var webStream = webResponse.GetResponseStream();
        var responseReader = new StreamReader(webStream);
        string response = responseReader.ReadToEnd();

        JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
        dynamic dobj = jsonSerializer.Deserialize<dynamic>(response);
        string result = dobj["features"][0].ToString();

Best regards

If you happen to do POST requests, feel free to also post a working example :wink:

Are you using any Headers for the request ?
Also we have a GET endpoint, that returns a png map tile. I guess in that case the jsonSerializer is not needed, so i might exclude it from the template.