romain
January 31, 2021, 11:30am
1
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!
texnixe
January 31, 2021, 12:00pm
2
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
romain
February 1, 2021, 8:34pm
3
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!
romain
March 2, 2021, 5:21pm
4
Coming back here as I can’t find a solution
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.
1 Like
romain
March 7, 2021, 2:45pm
6
thanks for letting me know Makes sense!
Cheers!