Import from files generated by querying Repository API

Hi Prismic team,

We have two websites which use prismic. And I am currently working on a script to automate our backup process.

We have both Medium plan for these two sites, and I noticed that you already have an import/export feature. But there is no Api to call this one. So in order to automate as maximum, I am using Repository API to generate json files for my documents.

It works fine for this part, I can get all my documents from Repository API correctly. The problem is that when I make a .zip file for all json files and put it in import section. It will prompt errors on my json files saying that there is some errors in my json format. So I compared the document that I generated from API and the same document that I get from your official export feature. There is some differences.

For example:

A part of file from export feature

"image": {
    "origin": {
      "id": "my_image_id",
      "url": "my_image_url",
      "width": 1220,
      "height": 721
    },
    "width": 1220,
    "height": 721,
    "url": "my_image_url?auto=compress,format",
    "edit": {
      "background": "transparent",
      "zoom": 1,
      "crop": {
        "x": 0,
        "y": 0
      }
    }

A part of file from repo API

"image": {
    "dimensions": {
      "width": 1220,
      "height": 721
    },
    "alt": "xxxx",
    "copyright": null,
    "url": "my_image_url?auto=compress,format"
  }

I am calling this endpoint to get my docs - > https://$repository.cdn.prismic.io/api/v2/documents/search?ref=$ref&access_token=$access_token&format=json&pageSize=1&lang=*

Do I miss something while exporting my docs or it is actually not possible to import files that are generated by Repo API?

Thanks a lot for your help!

Best Regards,

Hi @juncheng.liu

Welcome to the Prismic community,

I apologize for the delay, I'm still investigating and I will get back to you as soon as possible.

Fares

Alright, so I don't think that somebody before tried to do this, but actually, that might work but with some limitations.

Some extra fields are exported using the Import/Export feature that doesn't doesn't concern the content that is consumed by the API, such as edit, but this data is not valid even for the Import/Export feature because they are ignored when you Import again (so you can delete this field for example)

You will probably need to do some manipulations for some fields to reflect the Import JSON structure that we don't have a complete list of, so you need to try and handle errors once they appear.

But I totally agree with your use case. I will create a feature request to have some system to have a read-only export API or such an automation to send images of your data regularly by email, for example.

Please let us know if you need any further help,
Fares

Hello Fares,

Thanks for your response.

I understand that at the moment if I want to do export from Repo API and then import by using Import feature I need to find out myself all json structures which need to be modify and do some manipulations. I think this will be a huge job because Prismic does not have a complete list for this one, and we need to figure out all types of fields to modify in all different types of docs... It is a pity that we can not import our files directly in our use case.

I think it will be great if we can have a read-only export API which will generate correctly the files. In this case it won't bother the import process.

Thank you!

Juncheng

1 Like

Thanks for the feedback.