Migration API returns 403 Forbidden, yesterday it worked perfectly

Hi, guys! Could you please help me with migration api? Yesterday I created script and it was working fine. I created draft documents, API was working fine.

Today I receive 403 error from endpoint https://migration.prismic.io/documents Nothing has changed on my side, all credentials, api-keys etc are correct, code is the same. May be it's too hot for API requests? Or may be we deal with some black magic? It's a joke, but could you have a look please.

Hi @dmitry.d,

My guess is that you have a user session token.

User session tokens are one of two ways to authenticate with the Migration API.

You can also use a permanent token to authenticate.

Thanks.

Hi, Phil, and thank you. I just tried permanent token. The result is the same: error 403.

Can you give me your repo URL so I can check the logs?

Sure: https://apotheca.prismic.io/ here it is

1 Like

OK, I've found nothing at all in the logs to suggest any problems, can you try generating a new user session token?

Done it, result is the same: 403 error. Token is generated, but migration API returns 403 if I use correct credentials. If I test incorrect credentials, it says: {"Message":"User is not authorized to access this resource with an explicit deny"}. So the problem is not in auth, server authenticates me and returns {"Message":"Forbidden"}

Can you tell me how you're performing your query?

I made CLI utility.
Here is code (all env variables are triple checked and correct, yesterday I created test pages with this script and did not changed anything)

`import fetch from 'node-fetch';
import dotenv from 'dotenv';

import prepareBrandsData from "../helpers/prepareBrandsData.js";

dotenv.config();

const processData = async () => {
  const isBrandsDataReady = prepareBrandsData();
  if (!isBrandsDataReady) return;
  if (isBrandsDataReady) {
    console.log('Data prepared successfully 😊');
  }

  const migrationEndpoint = process.env.MIGRATION_ENDPOINT;
  const repository = process.env.REPOSITORY_NAME;
  const email = process.env.ADMIN_EMAIL;
  const password = process.env.ADMIN_PASSWORD;
  const apiKey = process.env.API_KEY;

  const exampleBrandData = 
    {
      "title": "Example Migrated Brand",
      "uid": "example-migrated-brand",
      "type": "brand_page",
      "lang": "en-US",
      "data": {
        "url_key": "example-url-key",
        "creation_time": "2024-12-23",
        "update_time": "2024-12-23",
        "meta_title": "Migrated Meta Title Here",
        "meta_description": "Migrated Meta Description Here",
        "slices": [
          {
            "variation": "default",
            "primary": {
              "brand_title": "migrated brand title",
              "brand_description": "migrated brand description",
            },
            "slice_type": "brand_intro"
          }
        ],
      }
    };

  try {
    const authResponse = await fetch('https://auth.prismic.io/login', {
      headers: {
        'Content-Type': 'application/json',
      },
      method: 'POST',
      body: JSON.stringify({
        email,
        password,
      }),
    });

    const token = await authResponse.text();

    const response = await fetch(migrationEndpoint, {
      headers: {
        Authorization: `Bearer ${token}`,
        'Content-Type': 'application/json',
        'x-api-key': apiKey,
        repository,
      },
      method: 'POST',
      body: JSON.stringify(exampleBrandData),
    });

    if (!response.ok) {
      console.error('Error with migration endpoint:', await response.text());
      return;
    }

    const responseData = await response.json();
    console.log(responseData, 'response from migration api');
  } catch (error) {
    console.error('Error processing data:', error);
  }
};

export default processData;

Auth API works fine, token is here when I log it.

Hi, @Phil I am sorry, the problem was on my side. Env variables were triple checked, but they need to be ten times checked if needed :sweat_smile: No magic as always, just stupid and obvious error on my side. Migration API is working fine for my now.

1 Like