403 Forbidden - Daily quota reached or API key unauthorized


#1

I am using the free version and the message always appears
403 ({‘error’: ‘Daily quota reached or API key unauthorized’})

that could be happening?

Thank you!
Regards,
Juan


#2

Exactly what it says, I guess. Either your API key is not valid or you reached the daily quota.

An example query would surely help.


#3

the key api is correct, and I have not reached the daily quota, this is my code

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace Ruta
{
class Program
{
static async Task Main(string[] args)
{

        var baseAddress = new Uri("https://api.openrouteservice.org");

        using (var httpClient = new HttpClient { BaseAddress = baseAddress })
        {

            httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8");
            httpClient.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Authorization","5b3ce3597851110001cf6248985eba971d6a432982352355657a5ded");

            using (var content = new StringContent("{locations:[[9.70093,48.477473],[9.207916,49.153868],[37.573242,55.801281],[115.663757,38.106467]]}"))
            {
                using (var response = await httpClient.PostAsync("/v2/matrix/driving-car", content))
                {
                    string responseData = await response.Content.ReadAsStringAsync();
                }
            }
        }

    }
}

}


#4

Ok, your key is valid, yep (not a good idea to make that public btw…).

Can you print the full URL, passed parameters and headers? It needs Content-Type: application/json and well, the POST request actually has to post a JSON object (not sure if your lib does that automatically from that string you pass). That shouldn’t result in this API error, but the rest actually looks fine to me.


#5

I removed that code from the Open Route page,
this is what returns me:

|response|{StatusCode: 403, ReasonPhrase: ‘Forbidden’, Version: 1.1, Content: System.Net.Http.StreamContent, Headers: { Connection: keep-alive Date: Wed, 08 May 2019 15:56:15 GMT Server: nginx/1.10.3 Server: (Ubuntu) Content-Length: 61 Content-Type: application/json }}|System.Net.Http.HttpResponseMessage|


#6

We can’t help if you don’t give us one full exact HTTP request that fails: full URL, POST parameters and headers. Please print them in your debug window and paste them here (minus the Authorization header pls).


#7


#8

Paste. Please. This is not a nice way to request free support… And READ!! Your content-type is text/plain! If you use our POST endpoint, you have to POST a JSON, not a string! That’s what I was telling you here:

Can you print the full URL, passed parameters and headers? It needs Content-Type: application/json and well, the POST request actually has to post a JSON object (not sure if your lib does that automatically from that string you pass). That shouldn’t result in this API error, but the rest actually looks fine to me.


#9

The example is the one that you propose on your page


#10

Hi @Juan_Atenas,

This is C# i suppose? Due to limited human resources we cannot test every code example. They are generated automatically from a template which might not be working for C#.
The problem should be with either the AuthenticationHeaderValue or the TryAddWithoutValidation part.
If you get this to work, you might want to provide us with your solution, so other people won’t run into the same issue :slight_smile:

regards, Amandus


#11

Team

I am also getting Error “Daily quota reached or API key unauthorized!” . Please find the uploaded screen shot for reference.

My Input Latitude and Longitude is : {locations:[[8.609168, 49.893230],[8.589405, 50.055435]]}

var baseAddress = new Uri(“https://api.openrouteservice.org”);
string responseData = “”;
using (var httpClient = new HttpClient { BaseAddress = baseAddress })
{
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));
httpClient.DefaultRequestHeaders.Authorization =new AuthenticationHeaderValue(“Authorization”, “xxx”);

            var SensorLocationsData = _notiUnitOfWork.NotificationRepository.GetLastSensorLocationData();
            string locations = "{locations:[locs]}";
            string loc = string.Empty;
            foreach (var SensorLocations in SensorLocationsData)
            {
                string str = string.Format("[{0}, {1}]", SensorLocations.Longitude, SensorLocations.Latitude);
                if (str != "")
                    loc += str + ","; 
            }

            locations = locations.Replace("locs", loc.Substring(0, loc.Length - 1));
            using (var content = new StringContent(locations))
            {
                using (HttpResponseMessage response = httpClient.PostAsync("/v2/matrix/driving-car", content).Result)
                {
                    responseData = response.Content.ReadAsStringAsync().Result;
                }
            }
        }
        string jsonString = JsonConvert.SerializeObject(responseData);
        return new JsonResult() { Data = jsonString, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

Thanks,
Vamsi


#12

Please provide us with:

  • the exact URL incl endpoint
  • the POST body
  • the headers

in a human-readable and reproducible format, i.e. text. C# must have the option to print a “debuggable” version of the request, e.g. https://stackoverflow.com/questions/18924996/logging-request-response-messages-when-using-httpclient/35215502


#13

Hallo Nils,

Please find the below details:

Exact URL incl endpoint : https://api.openrouteservice.org/v2/matrix/driving-car

Headers: {Content-Type: text/plain; charset=utf-8 Content-Length: 57}

“error”: “Daily quota reached or API key unauthorized”


My complete code i posted in above posts.

Cheers
Vamsi


#14

Multiple things potentially wrong here:

Content-Type: application/json not text.

Authorization: Bearer <key>, not Authorization <key>.


#15

Also, I don’t see your POST body… Please don’t make me look at screenshots:

in a human-readable and reproducible format, i.e. text.


#16

Hi Nils,

i changed from text to json as content type and Bearer Key

Headers = {accept: application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8 Authorization: Bearer key}

RequestMessage:

{Method: POST, RequestUri: ‘https://api.openrouteservice.org/v2/matrix/driving-car’, Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
accept: application/json
accept: application/geo+json
accept: application/gpx+xml
accept: img/png; charset=utf-8
Authorization: Bearer key
Content-Type: application/json; charset=utf-8
Content-Length: 57
}}

Responce : {StatusCode: 500, ReasonPhrase: ‘Internal Server Error’, Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: keep-alive
X-Ratelimit-Limit: 500
X-Ratelimit-Remaining: 495
X-Ratelimit-Reset: 1575367946
Date: Mon, 02 Dec 2019 11:41:25 GMT
Server: nginx/1.10.3
Server: (Ubuntu)
Content-Length: 438
Content-Type: application/json
}}

I am using below code:

var baseAddress = new Uri(“https://api.openrouteservice.org”);
httpClient.DefaultRequestHeaders.Add(“Authorization”, "Bearer " + “xxx”);

using (var contents = new StringContent("{locations:[[8.609168,49.893230],[8.589405,50.055435]]}", Encoding.UTF8, “application/json”))
{
HttpResponseMessage response = httpClient.PostAsync("/v2/matrix/driving-car", contents).Result;
responseJson = response.Content.ReadAsStringAsync().Result;
}
string jsonString = JsonConvert.SerializeObject(responseJson);
return new JsonResult() { Data = jsonString, JsonRequestBehavior = JsonRequestBehavior.AllowGet };


#17

I still don’t see any POST parameters… I don’t see how I can help you… It works for everyone else, so I’m pretty sure that’s a basic programming mistake on your side and we can’t fix that for you.


#18

Nils,

i am passing inputparameters: {coordinates:[[8.609168, 49.893230],[8.589405, 50.055435]]}

httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));
httpClient.DefaultRequestHeaders.Add(“Authorization”, “Bearer " + “key”);
var serializedAuthor = JsonConvert.SerializeObject(data);
var serializedData = serializedAuthor.Replace(@”""", “”);

            using (var content = new StringContent(serializedData, Encoding.UTF8, "application/json"))
            {
                    using (HttpResponseMessage response = await httpClient.PostAsync("/v2/directions/driving-car", content))
                    { 
                      responseData =  await response.Content.ReadAsStringAsync();
                    }
                } 
            } 

Headers {Accept: application/json Authorization: Bearer key}

RequestMessage {Method: POST, RequestUri: ‘https://api.openrouteservice.org/v2/directions/driving-car’, Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
Accept: application/json
Authorization: Bearer key
Content-Type: application/json; charset=utf-8
Content-Length: 59
}}

Stil i am not getting any responce from server.

my complete code also i mentioned in above screen shorts.

Thanks
Vamsi


#19

No idea… Please format the code, this is markdown. It’s painful to look at… Unfortunately that’s not only applying to the formatting…

No idea about C#, but this looks wrong: Content: System.Net.Http.StringContent as the content for a POST request. Why a string? Compare with

There it’s a Content: System.Net.Http.ObjectContent, which makes a whole lot more sense. But like I said, no idea about C#… Please post a question on stack overflow, this is not a an issue with our software, but your code…