To write data, your can send a POST request sending the JSON data to the same URL as your GET API. This will insert a new line on your sheet with the information you've sent.
You can also send an array of objects to post add multiple rows at once:
-----------
Shell
# Add one line to the sheet curl 'https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf' \ -H 'Content-Type: application/json' \ -d '{"Id":10, "Name": "Jack Doe", "Age": 97, "Created at": "2019-08-19T13:32:11.744Z"}' # Add two lines to the sheet curl 'https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf' \ -H 'Content-Type: application/json' \ -d '[{"Id":10, "Name": "Jack Doe", "Age": 97, "Created at": "2019-08-19T13:32:11.744Z"}, {"Id":11, "Name": "John Doe", "Age": 44, "Created at": "2019-08-19T13:32:11.744Z"}]'
Python
from datetime import datetime import requests # Add one line to the sheet requests.post( "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf", json={ 'Id': '10', 'Name': 'Jack Doe', 'Age': '97', 'Created at': datetime.now().isoformat(), }, ) # Add two lines to the sheet requests.post( "https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf", json=[{ 'Id': '10', 'Name': 'Jack Doe', 'Age': '97', 'Created at': datetime.now().isoformat(), }, { 'Id': '11', 'Name': 'John Doe', 'Age': '44', 'Created at': datetime.now().isoformat(), }], )
Javascript
const data = { Id: 10, Name: "Jack Doe", Age: 97, "Created at": new Date(), }; // Add one line to the sheet fetch("https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf", { method: "POST", mode: "cors", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }) .then((r) => r.json()) .then((data) => { // The response comes here console.log(data); }) .catch((error) => { // Errors are reported there console.log(error); }); // Add two lines to the sheet fetch("https://sheet.best/api/sheets/cf969697-682a-40e3-bad4-d54803eeeacf", { method: "POST", mode: "cors", headers: { "Content-Type": "application/json", }, body: JSON.stringify([ { Id: "10", Name: "Jack Doe", Age: "97", "Created at": datetime.now().isoformat(), }, { Id: "11", Name: "John Doe", Age: "44", "Created at": datetime.now().isoformat(), }, ]), }) .then((r) => r.json()) .then((data) => { // The response comes here console.log(data); }) .catch((error) => { // Errors are reported there console.log(error); });
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article