Trying to update just one item in a block

Hello,
How can we update just one item in a block?
The below code works, but it replaces all the top_tiles with just the one we are sending instead of updating just the one and leaving the others unchanged.
Isnā€™t there a way to only update the one with itā€™s id?
It seems it would be tedious to have to send the full array every time?
Please advise, thanks

PUT https://site-api.datocms.com/items/179731214

{
  "data": {
    "type": "item",
    "id": "179731214",
    "attributes": {
      "top_tiles": [
        {
          "type": "item",
          "id": "179731205",
          "attributes": {
            "title": "eBiz 1",
            "font_awesome_tile_code": "fas fa-shopping-cart ",
            "tile_url": "https://us.t-test.com/Login/Identity?PortalId=test ",
            "title_color_hex_code": " #ffffff"
          },
          "relationships": {
            "item_type": {
              "data": {
                "id": "2047005",
                "type": "item_type"
              }
            }
          }
        }
      ]
    },
    "relationships": {
      "item_type": {
        "data": {
          "id": "2047003",
          "type": "item_type"
        }
      }
    }
  }
}

Hello @jterry

You can pass just the IDs as string items in the array for the blocks you donā€™t want to modify.

However the IDs must be passed, as if you omit them, the system will think you have the intent to delete all of the non passed IDs (or object) blocks.

The reason for this is that, if you just had to pass the block you want to update, or the block you want to create, the call ā€œDelete all other blocks, and keep just this oneā€ and the call ā€œJust add this one blockā€ would be indistinguishable, not allowing you to delete block values from the modular content field

Hi thanks.
Just to make sure, can you please show example on how to pass the IDā€™s as string items?

Sure:

[
  // we don't need to change anything to these two blocks, just pass their IDs:
  "9862635",
  "9862636",
  // we want to change some field values for this block!
  {
    "id": "9862637",
    "type": "item",
    "attributes": {
      // ... put the block fields to be changed here
    },
    "relationships": {
      "item_type": {
        "data": {
          // the block model
          "id": "435822",
          "type": "item_type",
        }
      }
    },
  },
]
1 Like