How to update a structure via the API?

Is it possible to update a specific entry in a structure via the API?

I can easily update a simple field as explained on this page, however I have no clue if it would be possible to update a specific entry in a structure… I tried but it’s either removing all previous entries or creating a separate entry…

Cheers!

It’s possible if you can identify this specific entry somehow, for example:

$fieldData = $page->structureFieldName()->yaml();

$fieldData = array_map(function($item) {
  if ( $item['somefield'] === 'whatever') {
    $item['otherfield'] = 'somevalue';
    return $item;
  }
  return $item;
}, $fieldData);

$data = Data::encode($fieldData, 'yaml');

// then update page with data

Thanks @texnixe, but I wasn’t clear enough sorry.

Is there a way to update an entry in a structure via a PATCH request? (So no PHP)

Cheers!

Coming back here as I can’t find a solution :frowning:
If one of you have an idea let me know, I’m a bit desperate haha!
Cheers

You can only ever update the page/fields within a page, not individual items inside a structure field: /api/pages/:id | Kirby

So no matter if you use PHP or not, you need to get the data from the field, make your changes and then update the field content.

thanks for letting me know :slight_smile: Makes sense!

Cheers!