Question about array field PUT rest api #752
-
I have an array field with different data, to which payload adds an ID to each entry. The only way for something like this to work is to send a request with the whole array and modifying the desired entry.
While writing this I thought about making a custom endpoint in my collection, but is there a simpler way around this? Thanks in advanced. Please let me know if i'm not being clear : ) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @gonzam88, As you've figured already, sending the PUT with items missing from the array will update the "content" to be missing your other data and there isn't a way to tell Payload to leave them in. The array IDs was added to allow undefined fields to be saved correctly array objects shift around. There isn't a PATCH operation that would give you this today. You would need to make a custom endpoint for that. Alternatively you could structure your data to be an array that contains relationships. In that way the collection would have an endpoint that can modify one single item from having it's own collection, but that would have other implications to editor experience. Is there something in your implementation that makes it hard to fetch the full document and PUT it all back with the changes you need? |
Beta Was this translation helpful? Give feedback.
Hey @gonzam88,
As you've figured already, sending the PUT with items missing from the array will update the "content" to be missing your other data and there isn't a way to tell Payload to leave them in. The array IDs was added to allow undefined fields to be saved correctly array objects shift around. There isn't a PATCH operation that would give you this today.
You would need to make a custom endpoint for that. Alternatively you could structure your data to be an array that contains relationships. In that way the collection would have an endpoint that can modify one single item from having it's own collection, but that would have other implications to editor experience.
Is there somethi…