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.










share|improve this question
























  • 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















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.










share|improve this question
























  • 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













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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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);
});





share|improve this answer





















  • I think onWrite would be better since the requirement is for both create and update
    – MrAleister
    yesterday








  • 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










  • Will try this out. Thanks
    – Manasa
    yesterday


















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.






share|improve this answer










New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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

























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);
});





share|improve this answer





















  • I think onWrite would be better since the requirement is for both create and update
    – MrAleister
    yesterday








  • 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










  • Will try this out. Thanks
    – Manasa
    yesterday















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);
});





share|improve this answer





















  • I think onWrite would be better since the requirement is for both create and update
    – MrAleister
    yesterday








  • 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










  • Will try this out. Thanks
    – Manasa
    yesterday













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);
});





share|improve this answer












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);
});






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Jack Woodward

34617




34617












  • I think onWrite would be better since the requirement is for both create and update
    – MrAleister
    yesterday








  • 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










  • Will try this out. Thanks
    – Manasa
    yesterday


















  • I think onWrite would be better since the requirement is for both create and update
    – MrAleister
    yesterday








  • 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










  • 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












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.






share|improve this answer










New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • 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















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.






share|improve this answer










New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • 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













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.






share|improve this answer










New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









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.







share|improve this answer










New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer








edited yesterday





















New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered yesterday









MrAleister

27019




27019




New contributor




MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






MrAleister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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










  • 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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]