Hey @radikris definitely, so in order to update an existing field in the write API, you simply do a PATCH request to our write API url with the content updates required. This will merge your changes into the existing content entry, so you wont need to update ALL fields.
Essentially, you would be doing something similar to what is outlined in this forum post: How to rename a field in a model and all its content retroactively
Let’s say you have blog articles with a custom field called localizedImage
that we want to localize.
// read all result might need to paginate if list > 100
const allContent = await fetch('https//builder.io/api/v2/content/blog-article?apiKey=${YOUR_API_KEY&}fields=data.localizedImage')
.then(res => res.json());
This will give you all of the content entries for a given model you want to update, and only the localizedImage field. The results should look something like this:
{
"results": [
{
"name": "blog article name",
"data": {
"localizedImage": "https://cdn.builder.io/api/v1/image/assets%2Fe37b966ec695434bb21e97442a4a9f46%2F04380702c8814b88af95b9efa5ffb063"
}
},
{
"name": "another blog article",
"data": {
"localizedImage": "https://cdn.builder.io/api/v1/image/assets%2Fe37b966ec695434bb21e97442a4a9f46%2Fa52c091476ff44eabb3da9dedb6948e1"
},
...
]
}
Once you have fetched them, you can map over them and update the content you want
allContent.results.map(entry => {
//grab the current image
const originalDefault = entry.data.localizedImage;
//update the entry to be localized
entry.data.localizedImage = {
"@type": "@builder.io/core:LocalizedValue",
"Default": originalDefault,
"en": someEnValue, //you can even update the localized values now if you want
"hu": someHuValue,
...
}
await fetch('https://builder.io/api/v2/write/blog-model', {
method: 'PATCH',
headers: {
Authorization: `bearer ${privateKey}`,
},
body: JSON.strinigify(entry),
})
})
You will need to update the model to have the entry be localized, but that should work. You can pull down the content with the first GET request, then update the model in your Builder space and then map over content and push up with the PATCH request, OR, you should be able to update the model after the fact, but it might momentarily look wonky on your Builder UI. I recommend testing both methods to find which works best for you
I would also recommend you play around with our API Explorer to make sure you have the object shape exactly correct, as well as only working with one entry at a time to test.
Test it out and let me know if that works or you have any further questions !