Error creating a link field in a migration

Hello, community,

somebody knows how resolve this error:

{“data”:[{“id”:“cf3acb”,“type”:“api_error”,“attributes”:{“code”:“INVALID_ENDPOINT”,“details”:{}}}]}

I am creating a link field related to model previously created, when run the migration this show the error showen above

this is my snipped code:

const linkField = await client.fields.create( spaceModel,{

  label : 'Layout',

  apiKey: 'layout',

  fieldType: 'link',

  validators:{

    itemItemType : { itemTypes : ["443453"] } 

  },

  appearance : {

    editor : 'link_select'

  }

});

hello @contacto and welcome!

How are you getting the item type id 443453? Is that hardcoded? Because that might not be present in the environment that you are creating with the migration? Makes sense?

Otherwise, could you please send a bit more context of your code so that I can try something on my end? Thanks!

Hello @mat_jack1 I share you the code’s migrations

banner migratrion

‘use strict’;

module.exports = async (client) => {

// DatoCMS migration script

const bannerModel = await client.itemTypes.create({

name: 'Banner',

apiKey: 'banner',

});

const textField = await client.fields.create(bannerModel.id, {

label: 'Text',

apiKey: 'text',

fieldType: 'text',

validators: {

  required: {}      

},

appearence : {

  editor : 'wysiwyg'

},

defaultValue: null

});

const urlField = await client.fields.create(bannerModel.id,{

label : 'Url',

apiKey: 'url',

fieldType : 'string',

validators : {

  required : {},

  format : { predefined_pattern : 'url' }

},

appearence :{

  editor : 'single_line',

  parametres : { heading : false },

  addons : []

}

});

const imagesField = await client.fields.create(bannerModel.id,{

label : 'Images',

apiKey : 'images',

fieldType : 'file',

validators : {

  required : {},

}

});

}

space migration

‘use strict’;

module.exports = async (client) => {

const modelIdOrApiKey = ‘banner’;

client.itemTypes.find(modelIdOrApiKey)

.then( async (itemType) => {

const spaceModel = await client.itemTypes.create({

  name: 'Space',

  apiKey: 'space',

});

const titleField = await client.fields.create(spaceModel.id, {

  label: 'Name',

  apiKey: 'name',

  fieldType: 'string',

  validators: {

    required: {},

  },

  appearance: {

    editor: 'single_line',

    parameters: {

      heading: true,

    },

    addons: [],

  },

});

const linkField = await client.fields.create( spaceModel,{

  label : 'Layout',

  apiKey: 'layout',

  fieldType: 'link',

  validators:{

    itemItemType : { itemTypes : [itemType.id] } 

  },

  appearance : {

    editor : 'link_select'

  }

});

})

.catch((error) => {

console.log('spaces error');

console.error(error);

});

}

Also I attached an screenshot result

Hello @mat_jack1

Also i tried run the following example of the documentation and this show me the same error.

module.exports = async (client) => {
// Create the author model
const authrModel = await client.itemTypes.create({ name: ‘Author’, apiKey: ‘author’ });
// Add a name field to the author model
await client.fields.create(‘author’, {
label: ‘Name’,
apiKey: ‘name’,
fieldType: ‘string’,
validators: {
required: {},
},
});
// Add an author field to the article model
await client.fields.create(‘article’, {
label: ‘Author’,
apiKey: ‘author’,
fieldType: ‘link’,
validators: {
itemItemType: { itemTypes: [authorModel.id] },
},
});
// Create an author record
const authorRecord = await client.items.create({
itemType: authorModel.id,
name: ‘Mark Smith’,
});
// Set the author field on every existing article
const allArticles = await client.items.all(
{ filter: { type: ‘article’ } },
{ allPages: true }
);
for (const article of allArticles) {
await client.items.update(article.id, {
author: authorRecord.id,
});
}
};

hey @contacto, I’ve found a bug here:

you should use spaceModel.id, can you please fix that and let me know?