Funcionamento da API em outros Navegadores

Hello, I have an application running smoothly with JSON responses, and the API key is all correct. However, when I bring this project into another browser (Sankhya OM), my key becomes invalid.

API Call:

javascriptCopy code

async function fetchData() {
    const query = new URLSearchParams({
  key: 'MY_KEY'
}).toString();
    
const resp = await fetch(
  `https://graphhopper.com/api/1/vrp?${query}`,

But I receive an error:

M {message: "Request failed with status code 401", name: "AxiosError", code: "ERR_BAD_REQUEST", config: {…}, request: XMLHttpRequest, …}
code: "ERR_BAD_REQUEST"
config: {transitional: {…}, adapter: "xhr", transformRequest: Array(1), transformResponse: Array(1), timeout: 0, …}
message: "Request failed with status code 401"
name: "AxiosError"
request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}
response: {data: {…}, status: 401, statusText: "", headers: i, config: {…}, …}
stack: "AxiosError: Request failed with status code 401↵    at https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:1:21802↵    at XMLHttpRequest.d (https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:1:21947)"
__proto__: Error


POST https://graphhopper.com/api/1/vrp? 401
{message: "Wrong credentials. Register and get a valid API key at https: //www. graphhopper. com/developers/"}

The error is related to “HTTP request not authorized.”

Can you check the Network tab of the dev tools in your browser to make sure the api key is actually appended to the url correctly?

My key does not appear only when calling the API

async function fetchData() {
const query = new URLSearchParams({
key: ‘MY_KEY’
}).toString();

const resp = await fetch(
https://graphhopper.com/api/1/vrp?${query},

Yes, and the points seem to be empty, too (‘point=’). Could it be that this browser does not support this string replacement syntax (ES6 template literals)? Maybe just try

const resp = await fetch('https://graphhopper.com/api/1/vrp?' + query)

instead.

1 Like

Exactly that, resolved!!

Thanks @easbar

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.