I just can’t get it to work. I need to fetch a list of objects from an API. The method has to be GET and i have the token for Authorization header. this is the fetch function right now. I console logged the bearer const, and result in Bearer <toke>
.
const fetchListChats = (accessToken) => {
const bearer = `Bearer ${accessToken}`;
fetch('https://api.quickmatic.ai/api/chat/list', {
method: 'GET',
headers: {
'Authorization': bearer,
'Accept': 'application/json',
}
})
.then(response => response.json())
.then(data => {
console.log('Data:', data);
})
.catch(error => {
console.log(error);
});
};
I tried a lot of things, but still not manage to make it work.
2
Answers
So the answer is simple. The other developer i worked with write the wrong Endpoint in the documentation.
if you have postman you can try this api in post man and set Bearer ,
then if you get response in postman your code have a proplem
in postman you can get code and then copy in your code after code is work ,
you can refactor ,
and i think in headers :
headers:{"Content-Type":"application/json"}
if you try this and dont be work , try your api in postman !
i hope this help