API v2 started returning 401 all of a sudden

Hello.

Starting about 24h ago from this post, the API has started returning 401 for my requests without any changes in code. I’m using the creator token to pull pledges to present them on my website.

I did update my MFA settings a while ago, but the API worked fine for a while after that. Other than that, I have no idea what could’ve gone wrong.

I have deleted and re-created the app, to no avail.

This is how my request looks like:

const getCampaigns = async function* () {
  let cursor = '';

  while (true) {
    const url = formatUrlWithQuery('https://patreon.com/api/oauth2/v2/campaigns', {
      'page[cursor]': cursor
    });

    const response = await fetch(url, {
      headers: {
        authorization: `Bearer ${getPatreonToken()}`
      }
    });

    if (!response.ok) {
      throw new Error(
        `Request 'GET ${url}' failed. Status: ${response.status}. Body: '${await response.text()}'.`
      );
    }

    // https://docs.patreon.com/#get-api-oauth2-v2-campaigns
    type ResponseBody = {
      data: {
        id: string;
      }[];
      meta: {
        pagination: {
          cursors?: {
            next?: string;
          };
        };
      };
    };

    const body: ResponseBody = await response.json();

    yield* body.data;

    if (!body.meta.pagination.cursors?.next) {
      break;
    }

    cursor = body.meta.pagination.cursors.next;
  }
};

This is the error I’m getting:

Error: Request 'GET https://patreon.com/api/oauth2/v2/campaigns?page%5Bcursor%5D=' failed. Status: 401. Body: '{"errors":[{"challenge_metadata":null,"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":"ee954fff-9a1b-59e8-b7f4-1684137586a0","status":"401","title":"Unauthorized"}]}'.

Thanks to Raycoms on Discord, I figured out that adding www. to the URL makes it work. Still very annoying that it worked just fine before and stopped all of a sudden with a confusing error message.

Yes, you’d need to update the request url that you were using.