API Body Help RealtimeDB (dynamically set object key values)

So I am havnig some issues with setting the body of an API PATCH request to firebase realtimeDB. I am not using the in-built thunkable blocks as I am mainly using cloud firestore to store my data, except for this part which was easier with the realtimeDB. Here is what my json tree looks like:
image

What I would like to do is change the availableQTY, based on user input, and save a log in the same tree. The problem I am getting is that using the create object block requires pre-set data for the object key, which would cause multiple alterations to only show the most recent one and not show all changes that were made.

Here is an example of what I would like the change to look like in the realtimeDB, as well as the successfull requets from postman:

-H "Content-Type: application/json"

image

So whenever a change is recorded, the object key is set to the day the change was made so that the next time another change is made, a new entry will be made and both will be recorded as different children of the usage-reports object. Does anyone know how to make this work in thunkable X? Here is my attempt with results. The red text is set to only show when status != 200:

Attempt 1 (Set body using text blocks)

API URL

API Body

API Response

It seems to me that the body is set as is on postman which was successful, yet fails in thunkable. I also tried a few combinations with generate JSON from Object, and get object from JSON, as well as removing the quotation marks before and after the app variable apiResponse - new-qty-input block but the response has been the same each time.

1 Like

Well, I did some more testing, and for some reason it worked when I set the JSON for the body into an label, then set the API Body as that label’s text. Before trying this it did not work when setting the json in a variable then the api body to that variable, so I had incorrectly assumed it would not work if I tried it with a label. Looking further into it, the body block has a newline from one of the other blocks in it that didn’t look like it was there, but it was. Setting the body block to the no-newline join text block block made it work.

My apologies folks, looks like there was no underlying issue, just an overlooked aspect on my end.

3 Likes