Trigger to detect changes in firebase
up vote
0
down vote
favorite
When a child is updated or created in firebase database, I need to trigger a REST API. How to go about it?
Tried using "stream" function, but in order to invoke stream everysec will have to create a cron job. I would like some trigger to be done through firebase to call API.
django firebase firebase-realtime-database psql
add a comment |
up vote
0
down vote
favorite
When a child is updated or created in firebase database, I need to trigger a REST API. How to go about it?
Tried using "stream" function, but in order to invoke stream everysec will have to create a cron job. I would like some trigger to be done through firebase to call API.
django firebase firebase-realtime-database psql
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When a child is updated or created in firebase database, I need to trigger a REST API. How to go about it?
Tried using "stream" function, but in order to invoke stream everysec will have to create a cron job. I would like some trigger to be done through firebase to call API.
django firebase firebase-realtime-database psql
When a child is updated or created in firebase database, I need to trigger a REST API. How to go about it?
Tried using "stream" function, but in order to invoke stream everysec will have to create a cron job. I would like some trigger to be done through firebase to call API.
django firebase firebase-realtime-database psql
django firebase firebase-realtime-database psql
edited Nov 19 at 15:46
Frank van Puffelen
222k25363389
222k25363389
asked Nov 19 at 10:24
Manasa
55
55
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53
add a comment |
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
If you are using the Firebase Realtime database you can use Cloud Functions that trigger on a write to your database. Here is some docs that explain it a bit more. An example from the docs is below. Basically on a create to the database at /messages/{pushId}/original
it will trigger this code that you could process your logic in or call your rest api. You can also do this with Firestore as well.
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
CorrectonWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd wantonUpdate
andonCreate
.
– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
1
down vote
https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
const ref = firebase.database().ref("node/you/want/to/observe");
ref.on('value', function(dataSnapshot) { //here you do your API call });
BTW - you don't have to 'invoke stream every sec'. You create on listener that will trigger whenever condition is met. Juts remember to turn it off when you're done.
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you are using the Firebase Realtime database you can use Cloud Functions that trigger on a write to your database. Here is some docs that explain it a bit more. An example from the docs is below. Basically on a create to the database at /messages/{pushId}/original
it will trigger this code that you could process your logic in or call your rest api. You can also do this with Firestore as well.
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
CorrectonWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd wantonUpdate
andonCreate
.
– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
2
down vote
accepted
If you are using the Firebase Realtime database you can use Cloud Functions that trigger on a write to your database. Here is some docs that explain it a bit more. An example from the docs is below. Basically on a create to the database at /messages/{pushId}/original
it will trigger this code that you could process your logic in or call your rest api. You can also do this with Firestore as well.
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
CorrectonWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd wantonUpdate
andonCreate
.
– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you are using the Firebase Realtime database you can use Cloud Functions that trigger on a write to your database. Here is some docs that explain it a bit more. An example from the docs is below. Basically on a create to the database at /messages/{pushId}/original
it will trigger this code that you could process your logic in or call your rest api. You can also do this with Firestore as well.
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
If you are using the Firebase Realtime database you can use Cloud Functions that trigger on a write to your database. Here is some docs that explain it a bit more. An example from the docs is below. Basically on a create to the database at /messages/{pushId}/original
it will trigger this code that you could process your logic in or call your rest api. You can also do this with Firestore as well.
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
answered Nov 19 at 10:55
Jack Woodward
51129
51129
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
CorrectonWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd wantonUpdate
andonCreate
.
– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
CorrectonWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd wantonUpdate
andonCreate
.
– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
I think onWrite would be better since the requirement is for both create and update
– MrAleister
Nov 19 at 10:57
1
1
Correct
onWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd want onUpdate
and onCreate
.– Jack Woodward
Nov 19 at 10:59
Correct
onWrite
would better suit this instance if its the same endpoint, but if they are different rest APIs for create and update. you'd want onUpdate
and onCreate
.– Jack Woodward
Nov 19 at 10:59
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
Will try this out. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
1
down vote
https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
const ref = firebase.database().ref("node/you/want/to/observe");
ref.on('value', function(dataSnapshot) { //here you do your API call });
BTW - you don't have to 'invoke stream every sec'. You create on listener that will trigger whenever condition is met. Juts remember to turn it off when you're done.
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
1
down vote
https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
const ref = firebase.database().ref("node/you/want/to/observe");
ref.on('value', function(dataSnapshot) { //here you do your API call });
BTW - you don't have to 'invoke stream every sec'. You create on listener that will trigger whenever condition is met. Juts remember to turn it off when you're done.
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
up vote
1
down vote
up vote
1
down vote
https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
const ref = firebase.database().ref("node/you/want/to/observe");
ref.on('value', function(dataSnapshot) { //here you do your API call });
BTW - you don't have to 'invoke stream every sec'. You create on listener that will trigger whenever condition is met. Juts remember to turn it off when you're done.
https://firebase.google.com/docs/reference/js/firebase.database.Reference#on
const ref = firebase.database().ref("node/you/want/to/observe");
ref.on('value', function(dataSnapshot) { //here you do your API call });
BTW - you don't have to 'invoke stream every sec'. You create on listener that will trigger whenever condition is met. Juts remember to turn it off when you're done.
edited Nov 19 at 11:05
answered Nov 19 at 10:56
MrAleister
395110
395110
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
Please be aware that above answer assumes you run this code in the browser. Solution by Jack Woodward is 'server side' and probably more suiting your needs (especially if your API call will require credentials)
– MrAleister
Nov 19 at 11:11
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
sure,willl try. Thanks
– Manasa
Nov 19 at 11:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372557%2ftrigger-to-detect-changes-in-firebase%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm sorry but this question is a mess. What it has to do with Django ? What did you tried so far ? Could you please, share some code.
– MrAleister
Nov 19 at 10:30
My intention is to sync firebase data with psql, i'm using django api to do one time data dump currently. But i need to update my psql database when data is updated in firebase. To do so i need trigger to invoke my api when firebase data is updated
– Manasa
Nov 19 at 10:39
You say you "Tried using 'stream' function", which I assume means streaming data from the REST API. That API should not require a CRON job to constantly poll, but it will require a process that keeps its connection open. If you want us to help with that implementation, update your question to show what you tried.
– Frank van Puffelen
Nov 19 at 15:46
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
Nov 20 at 13:53