Hello,
Currently working on migrating content between two Prismic repositories and using the createDocumentFromPrismic() api. Sample code snippet:
const uploadAssetsUsingPrismicClient = async (docsObj) => {
const writeClient = prismic.createWriteClient(config.destRepo,
{
writeToken: process.env.AUTH_TOKEN_DEST,
migrationAPIKey: <<apiKeyFoundInDocs>>,
});
const migration = prismic.createMigration();
const d = docsObj[0];
migration.createDocumentFromPrismic(d, d.data.title);
await writeClient.migrate(migration, {
reporter(e) {
console.log('e.pending', e);
console.log('e.migrated', e);
},
});
}
After running script, I get this error:
{
property: 'data.body_content.0.spans.0',
value: {
start: 87,
end: 110,
type: 'hyperlink',
data: { link_type: 'Any' }
},
error: "Hyperlink span must contain a 'data' field with link data"
},
The below JSON object snippet is part of the whole document JSON fetched from the Prismic REST API and passed into the createDocumentFromPrismic function mentioned above (actual text content redacted):
"body_content": [
{
"type": "paragraph",
"text": "Social media never sleeps — xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxxxxxxxxxxx",
"spans": [
{
"start": 87,
"end": 110,
"type": "hyperlink",
"data": {
"id": "YSYcDBAAACMAic6a",
"type": "blog_post",
"tags": ["pillar"],
"lang": "en-us",
"slug": "social-media-xxx-xxxxx",
"first_publication_date": "2021-09-20T08:17:20+0000",
"last_publication_date": "2025-02-10T12:43:51+0000",
"uid": "social-media-management",
"link_type": "Document",
"isBroken": false
}
},
{ "start": 154, "end": 173, "type": "strong" }
],
"direction": "ltr"
},
What am I doing wrong?
Thanks