Forum Discussion

BLeSSuRe's avatar
BLeSSuRe
Occasional Visitor
6 months ago

React API call GET request in use headers x-api-key. cosole.log net::ERR_ABORTED 401 (Unauthorized)

Could you please explain me there is my mistake ? I get net::ERR_ABORTED 401 (Unauthorized)

Thank you very much.

 

import "./App.css";
import ky from "ky";
import {API_KEY} from "./components/key";
import {PrefixUrl} from "./components/key";


async function getAllData() {
try {
const todos = await ky.get(PrefixUrl,{
method:'GET',
mode: 'no-cors',
headers:{
type: 'X-Api-Key',
'X-API-KEY':API_KEY
// 'Authorization': `${API_KEY}`,
}
}).json()
console.log(todos)
} catch (err){
console.log(err.message);
}
}

function App () {
return (
<div className="App">
<h1>Hej</h1>
<button onClick={getAllData}>Get data</button>
</div>
)}

export default App

 

P.S. The URL and key are correct.

No RepliesBe the first to reply