Updating modular blocks via api

Hi guys, some help needed with the DatoCMS contentmanagemet API.
Iโ€™m using the official javascript client and Iโ€™m trying to update some records. These records are generated from the admin and are part of another record, they are blocks of a modular content field. If I query my items I see these block ID-s, then i can retrieve them using these IDs.
But when I try to update them, I get ActiveRecord::RecordNotFound 404 errors.
It seems to me they are not of the type โ€˜itemโ€™, but in the javascript client method client.items.update() I cannot find an item type or type id or model id parameter anywhere.
Is there a way to circumvent this? Or do i have to delete the original IDs from the item and add new ones?

hi @sharedcodingsans , welcome :slight_smile:

Few months ago we deprecated the ability to update block records directly via API ( https://www.datocms.com/product-updates/deprecation-notice-on-our-content-management-api ). That was required to ensure atomic, reliable operations on content.

So if you want to update a field in a modular block, you should update the whole item in a process like this:

  • fetch the item
  • fetch the block records defined in the modular content field
  • update the item, using the helper buildModularBlock and passing in the new attributes values

Ah, ok I get it. And the update will automatically disconnect (delete) the previous block records? So they will not clutter the database?
Also, I think it would be pretty useful to mention this in the docs, here:
https://www.datocms.com/docs/content-management-api/resources/item/update

Would have spared me a few hours today :wink:

Thanks for the info though, main thing is itโ€™s doable.

Cheers

True @sharedcodingsans, you are right.

We are going to add something in that page as soon as possible, Iโ€™ve added that to our backlog. Thank you very much for the feedback and sorry for the time waster!