Goal:
We need to remove a field option from a single line string field Block. The problem is that existing records point to that value, and weβd like to switch it for another. We thought the following process would be enough:
- Modify block to add new value option βyβ
- Get all existing records of that block type that point to value βxβ and change it for new value βyβ
- Modify block again to remove existing βxβ value.
Step 1 was completed successfully but step 2, we are stuck on.
Reading this documentation: https://www.datocms.com/docs/content-management-api/resources/item/instances we thought it was enough to do as such:
const imgCardModel = "img_cards_slim";
const brightGrey = 'brightgrey';
// Update all records that have color grey to have brightgrey
const records = await client.items.all({
filter: {
type: imgCardModel,
fields: {
colors: {
eq: 'grey',
}
},
},
},{allPages: true});
for(const record of records){
await client.items.update(record.id, {
colors: brightGrey,
});
}
But this gives a 404 error from the API, stating that it canβt find that record. Iβm not quite sure what is wrong?
Thank you!