"Hyperlink span must contain a 'data' field with link data"

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

Hi @chibu

The error is saying that the hyperlink span inside body_content is missing or has invalid link data — specifically, the link_type "Any" is not valid in this context.

Your actual span data looks fine to me, but I think Prismic expects a very specific shape for hyperlink span data —*and createDocumentFromPrismic() expects it in "rich text" format, not in the format returned by the REST API.

The problem is likely coming from the way the REST API gives you hyperlink data — it includes more document metadata than necessary. The Migration API wants a minimal shape like this:

"data": {
  "link_type": "Document",
  "id": "YSYcDBAAACMAic6a",
  "type": "blog_post",
  "uid": "social-media-management"
}

So could you try to strip away the extra properties like slug, tags, lang, etc., and just keep the essential fields? We'll see if that helps it go through.

Let me know!

Thank you @Ezekiel, I'll try it out and let you know!

1 Like