I am using google sheets APIS, I have successfully created the APIS that will get the data and post the data in my google sheet.
My google sheet looks like:
Coin Price Volume Cap
ETH $2,456.90 1459738 $8712BN
BTH $2,900.89 1245983 $24953BN
Now if the coin is already present in the sheet then API should update its value, if the coin is not present then the API should add the coin with all the details.
The API which I am using for appending the value is:
app.post('/save-data', async (req,res) => {
try{
const {newCoin, price, volume, cap} = req.body;
const { sheets } = await authentication();
const postReq = await sheets.spreadsheets.values.append({
spreadsheetId: sheetId,
range: "Sheet1",
valueInputOption: 'USER_ENTERED',
resource:{
values: [
[newCoin, price, volume, cap]
]
}
})
if(postReq.status==200)
{
res.status(200).send("The values are saved successfully");
}else{
res.status(400).send("Error in saving the values");
}
}catch(e){
console.log("Error while saving the data on the google sheets::", e);
res.status(400).send();
}
})
So I want to change the API so that first it searches if it finds the coin then just updates otherwise add a new row. Please help me to achieve this.
Thanks