Import a Bulk Update

This article explains how to add, delete, and modify fields in your documents in bulk with the Import feature.


Limitations

The first thing we need to cover is some of the general limitations of doing bulk changes with the Import feature:

  • Draft, Archived, and document in Releases aren't included in the process.
  • You will lose Image positioning and zoom of images during this process. You will need to re-apply any image cropping and zoom after running the import. 

With that in mind, let's take a look at how you can make bulk changes.

How import a bulk change

1. Export the content

First, you will need to export content from your repository.

2. Modify the JSON files

Next, you'll need to find a find-and-replace to make the bulk change(s) you need. For example, you could open the files in a code editor such as Visual Studio Code. Most code editors like this will have find-and-replace functionality to make this easy to do.

You need to make sure that you don't change any of the documents' file names. This will ensure that the re-import will work.

3. Import the updated documents

After making your changes, import the updated content to your repository.

Don't forget to re-apply any image cropping or zoom that you had previously as this is lost in the Import and Export process.

If all is well, then you just need to do is publish this release and your new updated content will be live!

Example use case

This use-case explains how to add responsive views for an Image field in all documents of the same Custom Type.

First, let's see how the files look before adding any changes. Here's the JSON of a Custom Type of the type "Page" with a Title and an Image field with a "Mobile" responsive view and one exported document:

  • Custom Type JSON
  • Exported file
Copy
{
  "Main": {
    "example_title": {
      "type": "StructuredText",
      "config": {
        "single": "heading1",
        "label": "Page title"
      }
    },
    "example_image": {
      "type": "Image",
      "config": {
        "constraint": {},
        "thumbnails": [
          {
            "name": "Mobile",
            "width": 300,
            "height": 400
          }
        ],
        "label": "Image"
      }
    }
  }
}
Copy
{
  "example_title": [
    {
      "type": "heading1",
      "content": {
        "text": "Updating responsive views",
        "spans": []
      }
    }
  ],
  "example_image": {
    "origin": {
      "id": "XsKyWBAAANKx2yr7",
      "url": "https://prismic-io.s3.amazonaws.com/your-repo-name/image.png",
      "width": 810,
      "height": 680
    },
    "width": 810,
    "height": 680,
    "url": "https://images.prismic.io/your-repo-name/image.png?auto=compress,format",
    "edit": {
      "background": "transparent",
      "zoom": 1.0,
      "crop": {
        "x": 0,
        "y": 0
      }
    },
    "credits": null,
    "alt": null,
    "provider": "imgix",
    "thumbnails": {
      "Mobile": {
        "origin": {
          "id": "XsKyWBAAANKx2yr7",
          "url": "https://prismic-io.s3.amazonaws.com/repository-name/image.png",
          "width": 810,
          "height": 680
        },
        "width": 300,
        "height": 400,
        "url": "https://images.prismic.io/repository-name/image.png?     auto=compress,format&rect=150,0,510,680&w=300&h=400",
        "edit": {
          "background": "transparent",
          "zoom": 0.5882352941176471,
          "crop": {
            "x": -88,
            "y": 0
          }
        },
        "credits": null,
        "alt": null,
        "provider": "imgix"
      }
    }
  },
  "type": "page",
  "tags": [],
  "lang": "en-us"
}

1. Modify the Custom Type

Now let's say you want to add a "Tablet" responsive view to the Image field of your documents. To do this, modify the JSON of the Custom Type to have the new responsive view. Here's an example of how the new JSON would look like:

Copy
{
  "Main":{
    "image":{
      "type":"Image",
      "config":{
        "constraint":{},
        "thumbnails":[
          {
            "name":"Mobile",
            "width":300,
            "height":400
          },
          {
            "name":"Tablet",
            "width":600,
            "height":340
          }
        ],
        "label":"Image"
      }
    }
  }
}

2. Modify the exported files (optional)

Then, to automatically populate the field for many documents, add the origin.id, and origin.name values for the Image field in the exported files for the documents. That way when you do the import, the "Tablet" view won't remain empty for existing documents using it.

Updating only the origin.id, and origin.url values for the Image field will regenerate the thumbnails of existing responsive views using the default cropping behavior. This will override the existing adjustments to responsive views (zooming or cropping) that content editors have made in the past. If you want to avoid this, don't modify the thumbnail data in the exported JSON files.

Don't modify the filename

To ensure that you update the existing document (rather than creating a new one), keep the same filename you got from the initial export job. It should look something like this: Xr6nORAAAChEyddW$45c60489-7511-463d-ad9f-61d05c9b90c5.json

Here's how the JSON for updating one document would look like:

Copy
{
  "page_name": [
    {
      "type": "heading1",
      "content": {
        "text": "Updating responsive views",
        "spans": []
      }
    }
  ],
  "example_image": {
    "origin": {
      "id": "XsKyWBAAANKx2yr7",
      "url": "https://prismic-io.s3.amazonaws.com/repository-name/image.png"
    }
  },
  "type": "page",
  "tags": [],
  "lang": "en-us"
}

3. Import the bulk change

Finally, Import your updated files to add the bulk change.

Prismic will create the thumbnails associated with the Image field in your updated Custom Types during the import job. Once is done, you should see your "Tablet" view in the documents.


Was this article helpful?
Not really
Yes, Thanks

Can't find what you're looking for? Get in touch with us on our Community Forum.