Hello there!
I decided to share a small guide of this process because I found it challenging but also really satisfying!
This is a step by step guide on how to bring the data from greenhouse api to firestore. Is an integration that I struggled as a junior developer but I think this might help you in any system you might connect to the firestore.
Step 1:
Create a firebase web app. Is super simple:
Please see this video →
https://www.youtube.com/watch?v=PKwu15ldZ7k&%3Bt=2808s
You don’t need to create the signup form just the setup of the firebase part.
Step 2:
You create a greenhouseData.ts file in order to create a class that will call your data with the .get() method later on.
For instance:
const URL = ‘XXXX
const greenhouseAuth = Bearer ‘Token’ -> here you replace Token with your admin api key.
export default class GreenhouseData {
async getdata(): Promise<AxiosResponse<any>> {
return axios.get(‘url / endpoint’, {
headers: {
Authorization: greenhouseAuth
}
});
}
}
Step 3:
Now on your firebase.ts file where you put all the configurations of firebase.
Change the function app to a class.
export default class FirebaseData {
db: any
initialise() {
const app = {
//all your config data such as apiKey:
//...
}
admin.initializeApp(app);
this.db = admin.firestore();
this async basically will be called on another file — you will see below why..
async post(data: any) {
const docRef = this.db.collection(‘yourCollection’).doc(‘yourcollectionID’);
await docRef.set(data);
}}
Step 4:
Create an index.ts file and this is the file that we will call on our local terminal to see if what we made is working.
On that file take that piece of code and replace the values you need to.
import FirebaseData from “./xxx”;
import GreenhouseData from ‘./xxx’;
async function main() {
const dfFirebase = new FirebaseData();
const dfGreenhouse = new GreenhouseData();
dfFirebase.initialize();
const datafromGH = await dfGreenhouse.getdata();
const participantsDataId = participantsDataId.data
for (let key in participantsDataId) {
//this again depends on the type of your data — array/ object
const participantDataId = participantsDataId[key].id;
//this is the function that you use to post on the firestore
dfFirebase.post({
myCollection: participantDataId
})
}
}
main();
Hope that will help you and save you time! :)
Top comments (0)