I am trying to use the citymapper API from a react App but I get the following error
Access to fetch at '<CITYMAPPER API URL>' from origin '<MY APP URL>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have tried to use it on a local development server and on a live server and neither works. I got the request to work using Postman/Insomnia client but as soon as I put it into the App, it does not work.
The code for the request is as follows
function getNav() {
const request = new Request(
`<CITYMAPPER API URL>`,
{
headers: {
"Citymapper-Partner-Key": "<MY KEY>",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
}
);
fetch(request)
.then((response) => response.json())
.then(
(data) => {
setNavigation(data);
}
)
.catch((error) => {
console.log(error);
});
}
If I add mode:"no-corse", I get a 401 error.
How can I solve the problem and make a request? Thanks in advance