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
yesterday
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
yesterday
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
yesterday
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago
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 yesterday
Frank van Puffelen
219k25361387
219k25361387
asked yesterday
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
yesterday
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
yesterday
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
yesterday
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago
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
yesterday
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
yesterday
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
yesterday
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago
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
yesterday
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
yesterday
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
yesterday
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
yesterday
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
yesterday
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
yesterday
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago
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
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
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.
New contributor
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
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
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
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
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
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 yesterday
Jack Woodward
34617
34617
I think onWrite would be better since the requirement is for both create and update
– MrAleister
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
add a comment |
I think onWrite would be better since the requirement is for both create and update
– MrAleister
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
I think onWrite would be better since the requirement is for both create and update
– MrAleister
yesterday
I think onWrite would be better since the requirement is for both create and update
– MrAleister
yesterday
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
yesterday
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
yesterday
Will try this out. Thanks
– Manasa
yesterday
Will try this out. Thanks
– Manasa
yesterday
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.
New contributor
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
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.
New contributor
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
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.
New contributor
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.
New contributor
edited yesterday
New contributor
answered yesterday
MrAleister
27019
27019
New contributor
New contributor
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
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
yesterday
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
yesterday
sure,willl try. Thanks
– Manasa
yesterday
sure,willl try. Thanks
– Manasa
yesterday
add a comment |
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
yesterday
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
yesterday
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
yesterday
Sorry for the confusion, i used "pyrebase" package to stream changes. Anyway i went ahead with cloud functions to resolve the issue. Thanks
– Manasa
12 hours ago