I have a third party API that I need to call every 5 seconds. I get JSON as response, and I'd like to write the JSON content to a Firebase node using Node.js. Based on Firebase examples I could import data with this code:
var usersRef = ref.child("users");
usersRef.set({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
},
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
}
});
Curl examples worked too. But what I really wanted to do is to import a third party API response directly to my Firebase database using the API endpoint. How can i do it with Node.js?
First, you need to make a request to the api endpoint and receive the data. Then, you can send that json data to firebase
var request = require('request');
var usersRef = ref.child("users");
request('<your_endpoint>', function (error, response, body) {
if (!error && response.statusCode == 200) {
var asJson = JSON.parse(body)
usersRef.set(asJson)
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With