'{ detail: 'Authentication credentials were not provided.' }

i am trying to call api ("https://wger.de/api/v2/day/") to get some data , it require me to provide token with header in order to authorize i am passing same , but whenever i am trying to make call i am getting error "data: { detail: 'Authentication credentials were no provided}"

app.get("/workout", async (req, res) => {
    try {
        const response = await axios({
            url: "https://wger.de/api/v2/day/",
            method: "get",
            headers: {
                "content-type": "application/json",
                Authorization: 'Bearer ' + token
              },
        });
        
        res.status(200).json(response.data);
        
    } catch (err) {
        console.log(err);
        res.status(500).json({ message: err });
       
    }
});


Solution 1:[1]

Where are you getting the token variable from? Is that something that exists in a larger scope or is that something you need to be passing to your get?

Taking a look at the api you provided - it looks like you need to pass your authenticaion another way and without the Bearer keyword

I would try to reformat it to fit the example and see if that works? Like this:

Authentication: 'Token' + token

I found this under the Tools - https://wger.de/en/software/api

# In the terminal, e.g. bash
curl -H "Authorization: Token 123456..." \
     -H "Accept: application/json; indent=4" \
     -X PATCH --data '{"key": value, ...}' \
     --dump-header -
     https://wger.de/api/v2/....
# In the python console
>>> import requests
>>> import json
>>> from pprint import pprint
>>>
>>> url = 'https://wger.de/api/v2/....'
>>> data = '{"key": "value"}'
>>> headers = {'Accept': 'application/json',
               'Authorization': 'Token 12345...'}
>>> r = requests.patch(url=url, data=data, headers=headers)
>>> r
>>> r.content
>>> pprint(json.loads(r.content))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Colleen