Newly added field to custom type not reflected on API

Describe your question/issue in detail

I am using the prismicio/client javascript library to use the documents API. We decided to add a new field "parent" to a custom type. it's a "Selectbox" field and I picked the first option as the default value.
In Prismic's side, all works accordingly, however, on the API side, all the documents returned have a "null" parent. After some research, I found that I need to publish the document for the update to be shown on the API's side.
But most of the documents need to have the first option which I put as the default one for a "parent" value. As a matter of fact, only 2 documents need to have a different value.
In practice, it means i have to follow these steps for each document (!) if i want the API to return the new field:
1- Open the document in prismic
2- add a space on the title (or any other) field to enable the save button
3- click on save, then click on publish

This is overkill if i have a considerable amount of documents for that custom type... Is there any way to just publish all the documents without having to open them and edit them one by one for no reason ?

What steps have you taken to resolve this issue already?

I have googled, looked in the forum, asked chatGPT

It sounds like you’ve run into a situation where newly added fields to your custom type are not reflected in the API until each document is republished, which can be tedious if there are many documents. Fortunately, you can use Prismic’s Migration API to solve this problem efficiently.

The Migration API allows you to programmatically update and republish your documents in bulk without manually editing and republishing them one by one. You can automate the process of setting the “parent” field to the default value and republish all the documents.

Here’s a high-level approach to resolve your issue:

  1. Retrieve the documents from the document API.
  2. Create a script to update the field in the JSON.
  3. Reimport the data using the Migration client Migrating to Prismic - Documentation - Prismic
  4. Publish the migration release.

This way, you’ll avoid the manual process of opening each document and republishing, saving time and ensuring consistency across your content.

If you need assistance in setting up the Migration API script, feel free to reach out!

1 Like

This works great ! Thank you.