Exploring Sheety's Public API

As a developer, you may need to interact with various APIs to integrate different functionalities into your application. One such API is the Sheety API, which allows you to turn Google Sheets into APIs, saving you time and effort.

In this article, we'll explore the basics of the Sheety API and how to use it with JavaScript. We'll also include sample code snippets to help you build your first application.

Getting Started with Sheety API

Sign Up

Before we dive into the API, you need to sign up for a Sheety account. Once you have a Sheety account, you can create a new project to access the API.

Accessing Your API Endpoints

To access your API endpoints, you need to navigate to your project's dashboard. Then, click on the "API" button to access your API endpoints.

Now, you can start using your API.

Example Code

Let's explore some example code to help you get started with the Sheety API.

GET Method: Read Data

The first thing you'll want to do is read data from your Google Sheet. Here's a sample code snippet to help you accomplish that:

let url = "https://api.sheety.co/<YOUR PROJECT ID>/<YOUR SHEET NAME>/<YOUR SHEET LABEL>";
fetch(url)
  .then((response) => response.json())
  .then((data) => {
    // Do Something with Your Data
  });

Replace <YOUR PROJECT ID>, <YOUR SHEET NAME>, and <YOUR SHEET LABEL> with the appropriate values. Once your request is successful, you can use the data in your application.

POST Method: Create Data

The next thing you may want to do is create data. Here's a sample code snippet to help you accomplish that:

let url = "https://api.sheety.co/<YOUR PROJECT ID>/<YOUR SHEET NAME>";
let payload = {
  sheet1Name: {
    columnName: "value",
    columnName2: "value2",
  },
  sheet2Name: {
    columnName: "value",
    columnName2: "value2",
  },
};
fetch(url, {
  method: "POST",
  body: JSON.stringify(payload),
  headers: {
    "Content-Type": "application/json",
  },
})
  .then((response) => response.json())
  .then((data) => {
    // Do Something with Your Data
  });

Replace <YOUR PROJECT ID> and <YOUR SHEET NAME> with the appropriate values. Once your request is successful, the data will be added to your Google Sheet.

PUT Method: Update Data

The Sheety API also allows you to update data. Here's a sample code snippet to help you accomplish that:

let url = "https://api.sheety.co/<YOUR PROJECT ID>/<YOUR SHEET NAME>/<ROW ID>";
let payload = {
  columnName: "new value",
  columnName2: "new value 2",
};
fetch(url, {
  method: "PUT",
  body: JSON.stringify(payload),
  headers: {
    "Content-Type": "application/json",
  },
})
  .then((response) => response.json())
  .then((data) => {
    // Do Something with Your Data
  });

Replace <YOUR PROJECT ID>, <YOUR SHEET NAME>, and <ROW ID> with the appropriate values. Once your request is successful, the corresponding row in your Google Sheet will be updated with the new data.

DELETE Method: Delete Data

Finally, you may want to delete data from your Google Sheet. Here's a sample code snippet to help you accomplish that:

let url = "https://api.sheety.co/<YOUR PROJECT ID>/<YOUR SHEET NAME>/<ROW ID>";
fetch(url, {
  method: "DELETE",
})
  .then((response) => response.json())
  .then((data) => {
    // Do Something with Your Data
  });

Replace <YOUR PROJECT ID>, <YOUR SHEET NAME>, and <ROW ID> with the appropriate values. Once your request is successful, the corresponding row in your Google Sheet will be deleted.

Conclusion

The Sheety API is a powerful tool that allows you to turn Google Sheets into APIs in just a few clicks. With the sample code snippets provided in this article, you're well on your way to building your first application with the Sheety API. Happy coding!

Related APIs