# API Body Help RealtimeDB (dynamically set object key values)

**URL:** https://community.thunkable.com/t/api-body-help-realtimedb-dynamically-set-object-key-values/1578360
**Category:** Questions about Thunkable X
**Created:** [October 24, 2021, 12:00pm UTC](https://community.thunkable.com/t/api-body-help-realtimedb-dynamically-set-object-key-values/1578360 "2021-10-24T12:00:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kareem](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@kareem](https://community.thunkable.com/u/kareem)
#### Post date: [October 24, 2021, 12:00pm UTC](https://community.thunkable.com/t/api-body-help-realtimedb-dynamically-set-object-key-values/1578360/1 "2021-10-24T12:00:10Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/c/dc74ff124e70c37b958c054a7c72675ae7fbcda4.png)

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:

```auto
-H "Content-Type: application/json"

```

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/6/760b12b39e741fd6a842d9d127b05d84ff0eec43.png)

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/d/7dc6c4c670cc1e3daf4edef2bd621293af09c4bb.png)

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)**

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/1/913206e42c6f6329fb4b6d4fb35e23d4884a8d0f.png)

_API URL_

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/3/b3034900b90f79a36ac82b672c03c42d74dfdaef.png)

_API Body_

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/1/a1f94e91f91d1a1994bd4f300cc7acfbfc960aef.png)

_API Response_

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/4/c4b497a13e4b2b2ff3ea6e24c4c615f1d48c6478.png)

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.

---

<div class="post-metadata">

### Author: ![kareem](https://avatars.discourse-cdn.com/v4/letter/k/9de053/32.png) [@kareem](https://community.thunkable.com/u/kareem)
#### Post date: [October 24, 2021, 12:41pm UTC](https://community.thunkable.com/t/api-body-help-realtimedb-dynamically-set-object-key-values/1578360/2 "2021-10-24T12:41:27Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:14pm UTC](https://community.thunkable.com/t/api-body-help-realtimedb-dynamically-set-object-key-values/1578360/3 "2024-11-08T13:14:36Z")

</div>


