ozgur/python-firebase

rename the unique name at post request on firebase

Chitrank-Dixit opened this issue ยท 8 comments

support I am doing a post request on the firebase.

result = fb.post('/orders/', {'id': 2})

in result I always get the unique name generated at the time of post request. Like
{u'name': u'-KAdbw7DfCuuRhFWZH7j'}

But I need to give it name of my choice.
{u'name': 'aaa'}

Is there any means to do that.

Cause the item created needs to be access and updated using the put request so I need to pass this unique id to make a put request. If I would give the name of my choice I can use that name without passing an extra argument in my request json.

What you should do is specify the name when you create the Firebase reference. And thereafter, you should post to that url.

For example, suppose fb is your firebase reference. You should create it as such:
my_url = 'my_app.firebase.io/aaa'
fb = firebase.FirebaseApplication(my_url, None)

Now instead of posting, patch it...
result = fb.patch(my_url + '/orders', {'id': 2})

Your data should be in 'aaa' as in...
result = firebase.get(my_url + '/orders', 'id')
print result['id'] == 2

Let me know if that doesn't work for you.

I have the same question. Patching doesn't seem to work on my end. I am ideally looking to save the data in a tree format like below

image

But using post, I am ending up with this:

image

Any idea on how can I have it save without the unique name?

I'm having the same issue as well. Was there ever a solution to this?

post gives it a random key that I don't want
patch gives no errors, but does not write anything to my database
put gives me an error saying "TypeError: put() takes at least 4 arguments (4 given)"

@sanke93 @NYamaguchi415

I'm still able to do it:

import firebase

url = 'https://myapp.firebaseio.com'
fb = firebase.FirebaseApplication(url, None)
result = fb.patch('/users/alanisawesome/', {'date_of_birth': 'someday', 'full_name': 'Alan Turing'})

screenshot 2016-04-07 20 29 00

What were your exact commands?

Oh cool thank you @nhatbui!!! I was using the full firebase url in the patch function, which wasn't working.

I had the same issue and i solve it directly with patch.
(@nhatbui advice just without firebase python module but directly firebase api).
after make authorised session i used:

[python]
response = authed_session.patch(
    "https://XXXX.firebaseio.com/ROOT/CHILD/.json",JSONDATA)

which create the node child with the name you asked (CHILD) and store the data in it.

Dear adirmola, Please post a example.,

Thanks @nhatbui you big legend.

I had that same thing.

image

I used

result = firebase.patch('/sensor/dht/', {'First_Vals': 5, 'Sec_Vals': 6})

and it worked great. No nasty big random word!
image

I'll use this instead of

result = firebase.post('/sensor/dht/', {'First_Vals': 5, 'Sec_Vals': 6})