Hi, It's first time I am using migration api, I want to bulk update of my documents.
I downloaded all documents (.json files) with document API without problem, however when I try to update my docs with migration api, it shows error.
const writeClient = prismic.createWriteClient("luko", {
writeToken: <write_token_from_wirte_api_page>,
});
const migration = prismic.createMigration();
const docsDir = "./scripts/prismic/docs";
const files = fs.readdirSync(docsDir);
files.forEach(async (file) => {
if (path.extname(file) === ".json") {
const filePath = path.join(docsDir, file);
const fileContents = fs.readFileSync(filePath, "utf-8");
migration.updateDocument(JSON.parse(fileContents));
await writeClient.migrate(migration, {
reporter: (event) => console.log(event),
});
try {
const jsonData = JSON.parse(fileContents);
console.log(`File: ${file}, Data:`, jsonData);
} catch (error) {
console.error(`Error parsing JSON from file: ${file}`, error);
}
}
});
Errors
And I have this is error message... I used same token for custom type fetching, so I guarantee that my token is valid.
url: 'https://luko.cdn.prismic.io/api/v2',
response: { error: 'Invalid access token' }
package.json
I am using 2 packages
"@prismicio/migrate": "^0.0.2",
"@prismicio/client": "^7.11.0",
Your Role
Developer