1

I tried researching, looking through the docs, and running something by Chat GPT, and I couldn't find any answer as to how to fix the 401 error.

import express from 'express';
import fetch from 'node-fetch';

const app = express();

const creatorId = 'creator-ID';
const accessToken = 'access-Token';

app.get('/creator', async (req, res) => {
    try {
        const response = await fetch(`https://www.patreon.com/api/oauth2/v2/campaigns/${creatorId}`, {
            headers: {
                'Authorization': `Bearer ${accessToken}`
            }
        });
        const json = await response.json();
        res.json(json);
    } catch (err) {
        res.status(500).json({ error: err.message });
    }
});

app.listen(3000, () => {
    console.log('Server listening on port 3000');
});

Error message

{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"d2b03413-652e-5a35-a0ea-efe87bbd5995","status":"401","title":"Unauthorized"}]}
Tenno
  • 11
  • 1
  • Are you sure that your access token is correct? the request seems valid expect maybe wrong access token – TBA Jan 25 '23 at 14:54

0 Answers0