Patch and insert data into the next available index in an array

I’m trying to use appsmith to patch data into an existing array in baserow… I want to insert into the next available index in the array…

so I start off with this as a patch url which has no issues:

http://192.168.1.3:3001/api/database/rows/table/11124/{{Table1.selectedRow.id}}/?user_field_names=true

Appropriate headers are inserted for authorization and content type…

Then, in JSON I’ve got the following:

{
new_data = {
“url”: {{appsmith.store.quotePDF.url}}
}
‘Quote (PDF)’.insert(0, new_data)
updated_json = json.dumps(‘Quote (PDF)’)

}

The new data is correct but I’m at a loss on how to insert the contents of new_data into the next available index in an array called ‘Quote (PDF)’…

Any pointers would be greatly appreciated.

Thanks.

@joseph_appsmith, could you please help here? :pray:

Hi @TC2020 , I’m not completely sure, but I don’t think you can PATCH a single element in an array field. I think that you have to build a new array with the existing values plus the one you want to add, then PATCH the entire field.

So in the API body in Appsmith, you could take the existing array and push() the new value before sending the API request. Or you could use unshift() to add it to the beginning of the array.

Thanks for the heads up!

Hey joseph. You are exactly correct. I was able to build the array and patch it as a whole.

Thanks for your reply and confirmation.

1 Like

Awesome, glad it worked! And thank you for confirming.

Let me know if you need a hand with anything else! Feel free to DM me here or on our Discord. I’d love to hear more about your use case and what you are building with Appsmith.