How to get full entries content and push using admin Sdk?

Hello, i am currently trying to build a minimal app to export content models and their entries from one space to another , and I’m running into caveats when it comes to fecthing the entries , I get an error returned probably because the query is not contructed correctly but I don”t find the relevent documentation on hoow to get the entries conteent.

My goal , Export Models from one space to another WITH the entries content belonging to each model – simple as that

What I’ve done so far : created a UI interface to fetch all the models and choose the models to import –6> Work fine :white_check_mark:

Then fecth the selected models and show a list of published entries :cross_mark:

Import models to the new space :white_check_mark:

Import content entries inside each models :cross_mark: [error]

Here is the error I get in runtime:

*My migrate-models.js *

import { getAdminClient } from "../../utils/builder.js";

export default async function handler(req, res) {
  try {
    const { sourceKey, targetKey, selectedModels } = req.body;

    const source = getAdminClient(sourceKey);
    const target = getAdminClient(targetKey);

    for (const model of selectedModels) {
      console.log(`Migrating ${model.name}`);

      // Create model in target
      try {
        await target.chain.mutation.addModel({
          body: {
            name: model.name,
            kind: model.kind,
            fields: [
        {
          name: "sectionData",
          type: "JSON",
          required: true
        },
        {
          name: "enabledOn",
          type: "JSON",
          required: false
        },
        {
          name: "sectionBlock",
          type: "JSON",
          required: false
        },
        {
          name: "maxBlocks",
          type: "JSON",
          required: false
        }
      ],
            helperText: `Migrated from source`,
          },
        }).execute({ id: true, name: true });
      } catch (e) {
        console.warn(`Model "${model.name}" may already exist.`);
      }

      // Fetch entries
      const result  = await source.query({
        model: [
    { id: model.id },
    {
      entries: {
        id: true,
        name: true,
        data: true,
        published: true,
        lastUpdated: true,
      },
    },
  ],
});

      const entries = result?.data?.model?.entries || [];
      for (const entry of entries) {
        await target.chain.mutation.addContentEntry({
          model: model.name,
          body: {
            name: entry.name,
            data: entry.data,
          },
        }).execute({ id: true });
      }
    }

    res.status(200).json({ message: "Migration complete!" });
  } catch (err) {
    console.error(err);
    res.status(500).json({ error: err.message });
  }
}

Error in my console:

  51 |     { id: model.id },
  52 |     {
 POST /api/migrate-models 500 in 630ms (compile: 7ms, render: 623ms)
Error: type `ModelType` does not have a field `entries`
    at handler (pages\api\migrate-models.js:49:36)
  47 |
  48 |       // Fetch entries
> 49 |       const result  = await source.query({
     |                                    ^
  50 |         model: [
  51 |     { id: model.id },
  52 |     {
 POST /api/migrate-models 500 in 1094ms (compile: 398ms, render: 696ms)

As you see the error is spotted in my addContentEntry mutation query

What are the right fields to add in the addContentEctry query to push Entries to correponding models ??

Anyone knows this would greatly appreciate ;
Would try to dig deeper into the GraphqQL explorer

Joaquim

Was not able to get an answer to my questions, so have to rely mostly on personal research .

Turns out the only way to create content entries is using the Write API :

My solution : makeing a REST Api Http request to model endpoint and write entries as ‘data’

If you’re interested in how to do this I’ve created a publi repo here :

On a side note : Since for technical questions it is hard to get an answer fast , it is very important for devs to make sure the doc is always up to date @builderdotio Thank you !! :folded_hands: