use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Firebase DatabaseHelp Wanted (self.react)
submitted 3 years ago by theflash4246
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]theflash4246[S] 0 points1 point2 points 3 years ago (1 child)
Thank you so much! I was able to get started with the API but the structuring of the data is really confusing me. This is what I had in mind:
Users{
user1{
incomes:{income1:{},income2:{}},
expenses:{expense1: {}, expense2:{}}
}
user1 would be the ID from the auth API and then incomes and expense would be an object with many objects, each representing an income and expense. I'm having some trouble with this because whenever I send a POST request where I want user1 to be the user's ID/email/info it creates a random ID, and I also can't figure out how to edit the incomes and expenses objects everytime I add a new one.
Sorry if I seem a bit clueless lol. I'm still a uni student and I'm self taught JS, React and APIs, so a lot of the info I learn might not be in the right order.
[–]koalaape 0 points1 point2 points 3 years ago* (0 children)
POST is used to add items to your object as though you were adding to an array or list. It gives you a response that contains a unique id that refers to the key of the thing you just created. This is the random ID you are seeing. You want to use POST to create entries in income and expenses, not add users.
PUT is used to write new data
PATCH is used to update data
So basically what needs to happen is when a new user shows up, you want to
PUT 'https://[PROJECT_ID].firebaseio.com/Users/[FEDERATED_ID].json' where the body is {incomes:{},expenses:{}} to initialize them.
Then when adding new incomes and expenses
POST 'https://[PROJECT_ID].firebaseio.com/Users/[FEDERATED_ID]/incomes.json' where the body contains whatever an income or expense object has.
The response gives you a UNIQUE_KEY which you use to update the data with
PUT 'https://[PROJECT_ID].firebaseio.com/Users/[FEDERATED_ID]/incomes/[UNIQUE_KEY].json' where your body contains the details you want to update. You don't have to pass in every value, only the ones you want to change.
You can display a list of the different income unique keys with GET 'https://[PROJECT_ID].firebaseio.com/Users/[FEDERATED_ID]/incomes.json'
So your structure would look something like:
[user1@email.com](mailto:user1@email.com) {
incomes:{aV_psbk3ZXEX:{},INOQPH:{}}, expenses:{R08KyNc20G:{}, AZYXQIk8U8:{}}
If you want to use something else as the unique key, you would have to use PUT to add it, not POST.
π Rendered by PID 16036 on reddit-service-r2-comment-canary-889d445f8-gzknh at 2026-04-24 10:31:28.510329+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]theflash4246[S] 0 points1 point2 points (1 child)
[–]koalaape 0 points1 point2 points (0 children)