Difficulty with FETCH API authorization

Asked

Viewed 63 times

1

Staff I’m having a little trouble to carry out an API authorization so I’m doing the code

fetch('https://api.api-futebol.com.br/v1/',{

"method":"GET",
"headers": {
    "Authorization: Bearer test_a8c37778328495ac24c5d0d3c3923b"
} 
}
).then()

the documentation asks in this way :

curl -X GET https://api.api-futebol.com.br/v1/campeonatos \
   -H "Authorization: Bearer test_a8c37778328495ac24c5d0d3c3923b"

1 answer

2


You are setting the headers incorrectly, the values are defined by chave: valor, then the right thing would be:

fetch('https://api.api-futebol.com.br/v1/',{
  "method":"GET",
  "headers": {
    // Chave : valor
    "Authorization" : "Bearer test_a8c37778328495ac24c5d0d3c3923b"
  } 
})

Read more about the method fetch in this link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.