### Sheet2DB SDK - Installation Source: https://sheet2db.com/docs/sdks/javascript Install the Sheet2DB Javascript SDK using npm. ```APIDOC ## Installation ``` npm install @sheet2db/sdk ``` ``` -------------------------------- ### Install Sheet2DB Javascript SDK Source: https://sheet2db.com/docs/sdks/javascript Installs the Sheet2DB Javascript SDK using npm. This package provides an interface for interacting with Google Sheets. ```bash npm install @sheet2db/sdk ``` -------------------------------- ### Sheet2DB API - Example Request (cURL) Source: https://sheet2db.com/docs/read Example of how to make a GET request to the Sheet2DB API to read content from a spreadsheet. This example demonstrates setting the format to 'records' and a limit of 10 rows. ```bash curl -XGET 'https://api.sheet2db.com/v1/{connection-id}?format=records&limit=10' ``` -------------------------------- ### Sheet2DB API - Example Response (split format) Source: https://sheet2db.com/docs/read An example of the JSON response when requesting data in the 'split' format. This format separates column names and row data into distinct arrays. ```json { "columns": ["id", "name", "age"], "data": [["1", "John", 24]] } ``` -------------------------------- ### Sheet2DB API - Example Response (dict format) Source: https://sheet2db.com/docs/read An example of the JSON response when requesting data in the 'dict' format. Data is organized by column, with each column containing nested objects keyed by row index. ```json { "id": { "0": "1", }, "name": { "0": "John", }, "age": { "0": 24, }, } ``` -------------------------------- ### Sheet2DB API - Example Response (index format) Source: https://sheet2db.com/docs/read An example of the JSON response when requesting data in the 'index' format. Data is organized as a JSON object where keys are row indices and values are objects representing the row's data. ```json { "0": { "id": "1", "name": "John", "age": 24, }, } ``` -------------------------------- ### Sheet2DB API - Example Response (series format) Source: https://sheet2db.com/docs/read An example of the JSON response when requesting data in the 'series' format. Data is presented as a JSON object where keys are column names and values are arrays of the column's data. ```json { "id": ["1"], "name": ["John"], "age": [24], } ``` -------------------------------- ### Sheet2DB API - Example Response (records format) Source: https://sheet2db.com/docs/read An example of the JSON response when requesting data in the 'records' format. Each row from the spreadsheet is represented as a JSON object within an array. ```json [ { "id": "5", "name": "James", "age": 19, "comment": "" }, { "id": "4", "name": "Steve", "age": 22, "comment": "special" } ] ``` -------------------------------- ### Install Handlebars for SheetDB Integration (HTML) Source: https://sheet2db.com/docs/html-snippet This snippet shows how to include the Handlebars library for SheetDB integration into an HTML page. It should be added once, preferably before the closing tag. No external dependencies are required besides the script itself. ```html ``` -------------------------------- ### Get Column Names using Javascript Source: https://sheet2db.com/docs/keys This snippet shows how to fetch column names from a Google Sheet using Javascript and the Sheet2DB API. It utilizes the Fetch API to make a GET request to the /keys endpoint, requiring a connection ID and supporting an optional sheet name. ```javascript fetch('https://api.sheet2db.com/v1/{connection-id}/keys') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Making First GET Request to Sheet2DB API using CURL Source: https://sheet2db.com/docs/index This snippet demonstrates how to make a simple GET request to the Sheet2DB API to retrieve data from a spreadsheet. It requires a valid 'connection-id' obtained after creating an API in the Sheet2DB dashboard. The output will be the JSON representation of the spreadsheet data. ```bash curl -XGET 'https://api.sheet2db.com/v1/' ``` -------------------------------- ### Get Column Names using cURL Source: https://sheet2db.com/docs/keys This snippet demonstrates how to make a GET request to the Sheet2DB API to retrieve all column names from a Google Sheet. It requires a connection ID and optionally accepts a sheet name as a query parameter. ```cURL curl -XGET 'https://api.sheet2db.com/v1/{connection-id}/keys' ``` -------------------------------- ### Display Spreadsheet Data with Handlebars (HTML) Source: https://sheet2db.com/docs/html-snippet This example demonstrates how to display data from a Google Spreadsheet using SheetDB and Handlebars within an HTML structure. It requires a `data-sheetdb-url` attribute on a parent element and uses Handlebars syntax `{{column_name}}` in child elements to specify which column data to render. The response must be a JSON array. ```html

{{name}}

``` -------------------------------- ### GET /v1/{connection-id}/keys Source: https://sheet2db.com/docs/keys Retrieves an array of all column names (keys) from the first row of a specified Google Spreadsheet sheet. This is useful for understanding the structure of your data. ```APIDOC ## GET /v1/{connection-id}/keys ### Description Returns an array with all column names. It's all the cells from the first row. ### Method GET ### Endpoint `https://api.sheet2db.com/v1/{connection-id}/keys` ### Parameters #### Query Parameters - **sheet** (string) - Optional - Specify the name of the sheet (tab) you wish to select within your Google Spreadsheet. ### Request Example ```curl curl -XGET 'https://api.sheet2db.com/v1/{connection-id}/keys' ``` ### Response #### Success Response (200) - **keys** (array) - An array of strings representing the column names. #### Response Example ```json [ "id", "name", "age", "comment" ] ``` ``` -------------------------------- ### Sheet2DB SDK - Count Method Source: https://sheet2db.com/docs/sdks/javascript Gets the total number of rows in a specified sheet. ```APIDOC ### Count Gets the count of rows in the spreadsheet. #### Parameters - **sheet** (`string`) - Optional. The name of the sheet to count rows in. #### Example ```javascript sheet2db.Count({ sheet: 'Sheet1' }) .then(count => console.log(count)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Add Cloudflare Turnstile Captcha to Form (HTML) Source: https://sheet2db.com/docs/captcha This HTML snippet integrates the Cloudflare Turnstile Captcha widget into your form. Replace 'YOUR_SITE_KEY' with your Cloudflare Turnstile site key. The provided script loads the Turnstile API. ```html
``` -------------------------------- ### Search Rows with Conditions (JavaScript) Source: https://sheet2db.com/docs/search Provides a JavaScript example for making a search request to the Sheet2DB API. This snippet shows how to construct the URL with query parameters to filter data based on conditions like name and age. ```javascript fetch('https://api.sheet2db.com/v1/{connection-id}/search?name=John&age>20') .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Get Keys from Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Retrieves the keys (column headers) from a specified sheet in Google Sheets. Handles potential errors during the fetch operation. ```typescript sheet2db.Keys({ sheet: 'Sheet1' }) .then(keys => console.log(keys)) .catch(error => console.error(error)); ``` -------------------------------- ### Get Range of Data from Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Retrieves data from a specific range within the Google spreadsheet using A1 notation. Handles potential errors during the fetch operation. ```typescript sheet2db.Range({ range: 'A1:B2' }) .then(range => console.log(range)) .catch(error => console.error(error)); ``` -------------------------------- ### Add Google reCAPTCHA to Form (HTML) Source: https://sheet2db.com/docs/captcha This HTML snippet adds the Google reCAPTCHA widget to your form. Ensure you replace 'YOUR_SITE_KEY' with your actual Google reCAPTCHA site key. The script tag loads the necessary reCAPTCHA API. ```html
``` -------------------------------- ### Get Spreadsheet Title from Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Fetches the title of the Google spreadsheet. Handles potential errors during the fetch operation. ```typescript sheet2db.Title() .then(title => console.log(title)) .catch(error => console.error(error)); ``` -------------------------------- ### Update Row using Javascript Source: https://sheet2db.com/docs/update-query Example of updating a specific row in a Google Sheet using the Sheet2DB API with Javascript's fetch API. It shows how to configure the PATCH request, headers, and the JSON payload for the update. ```javascript fetch('https://api.sheet2db.com/v1/{connection-id}?id=20', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Mark', age: 18 }) }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Update Row using cURL Source: https://sheet2db.com/docs/update-row Example of updating a row in a Google Sheet using a cURL command. It demonstrates the PATCH request method, endpoint, headers, and the JSON payload for the update. ```bash curl -XPATCH https://api.sheet2db.com/v1/{connection-id}/row/3 \ -H "Content-Type:application/json" \ -d '{"name":"Mark","age":18,"id":10}' ``` -------------------------------- ### Update Row using CURL Source: https://sheet2db.com/docs/update-query Example of updating a specific row in a Google Sheet using the Sheet2DB API via CURL. It demonstrates the PATCH method, endpoint, headers, and the JSON data for the update. ```bash curl -XPATCH https://api.sheet2db.com/v1/{connection-id}?id=20 \ -H "Content-Type:application/json" \ -d '{"name":"Mark","age":18}' ``` -------------------------------- ### Accessing Public Spreadsheets Source: https://sheet2db.com/docs/public-spreadsheet This section covers how to access public view spreadsheets using an API Key. All GET endpoints can be utilized with this method. Authentication is done by passing your API Key and the Spreadsheet ID (__id) as query parameters. ```APIDOC ## GET /v1/{apiKey} ### Description Retrieves data from a public spreadsheet using an API Key. ### Method GET ### Endpoint `/v1/{apiKey}` ### Parameters #### Path Parameters - **apiKey** (string) - Required - Your Sheet2DB API Key. #### Query Parameters - **__id** (string) - Required - The ID of the spreadsheet. - **format** (string) - Optional - The desired output format (e.g., 'records'). - **limit** (integer) - Optional - The maximum number of records to retrieve. ### Request Example ```bash curl -XGET 'https://api.sheet2db.com/v1/{apiKey}?__id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms&format=records&limit=10' ``` ### Response #### Success Response (200) - **data** (array) - An array of records from the spreadsheet. #### Response Example ```json { "data": [ { "column1": "value1", "column2": "value2" } ] } ``` ``` -------------------------------- ### GET /v1/{connection-id} Source: https://sheet2db.com/docs/read Read data from your spreadsheet. This endpoint allows you to retrieve data from a specified Google Spreadsheet using a connection ID. ```APIDOC ## GET /v1/{connection-id} ### Description Read data from your spreadsheet. This endpoint allows you to retrieve data from a specified Google Spreadsheet using a connection ID. ### Method GET ### Endpoint `https://api.sheet2db.com/v1/{connection-id}` ### Parameters #### Path Parameters - **connection-id** (string) - Required - The unique identifier for your Sheet2DB connection. #### Query Parameters - **sheet** (string) - Optional - Specify the name of the sheet (tab) you wish to select within your Google Spreadsheet. - **limit** (integer) - Optional - Set a limit on the maximum number of rows to be returned, providing control over result volume. - **offset** (integer) - Optional - Determine the starting point for fetching results, allowing you to skip a specified number of initial results. - **cast_numbers** (string) - Optional - Specify the column name(s) that you want to cast into numeric values. You can use multiple column names, separated by commas, to perform this operation. - **columns** (string) - Optional - Specify the column name(s) that you want to include in the result. You can use multiple column names, separated by commas, to perform this operation. - **format** (enum) - Optional - Specify how you want the response format to be. Allowed values `records`, `dict`, `series`, `split`, `index`. Default Value `records`. - **sort** (string) - Optional - Name of the column by which you want to sort the result. To specify sort order, add `:` after column name followed by order (`asc` or `desc`). Defaults to `desc`. Example: `https://api.sheet2db.com/v1/{connection-id}?sort=Age:asc` - **sort_method** (enum) - Optional - If you want to sort by date, set this attribute to `date`, Sheet2DB will try to automatically detect the data format but it is recommended to specify the format in the `sort_date_format` attribute. - **sort_date_format** (string) - Optional - Applies only when `sort_method=date`. Date format, e.g. if your date is 2022-19-12 use YYYY-mm-dd. For date time like 2022-19-12 13:55:00 use YYYY-mm-dd hh:mm:ss. ### Request Example ```curl curl -XGET 'https://api.sheet2db.com/v1/{connection-id}?format=records&limit=10' ``` ### Response #### Success Response (200) - **id** (string) - Description of the id field. - **name** (string) - Description of the name field. - **age** (integer) - Description of the age field. #### Response Example (`records` format) ```json [ { "id": "1", "name": "John", "age": 24 } ] ``` #### Response Example (`dict` format) ```json { "id": { "0": "1" }, "name": { "0": "John" }, "age": { "0": 24 } } ``` #### Response Example (`series` format) ```json { "id": ["1"], "name": ["John"], "age": [24] } ``` #### Response Example (`split` format) ```json { "columns": ["id", "name", "age"], "data": [["1", "John", 24]] } ``` #### Response Example (`index` format) ```json { "0": { "id": "1", "name": "John", "age": 24 } } ``` ``` -------------------------------- ### Count Rows in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Gets the total number of rows in a specified sheet in Google Sheets. Handles potential errors during the fetch operation. ```typescript sheet2db.Count({ sheet: 'Sheet1' }) .then(count => console.log(count)) .catch(error => console.error(error)); ``` -------------------------------- ### Delete Row with Query using Javascript Source: https://sheet2db.com/docs/delete-query Example Javascript code to delete a row from a Google Sheet via the Sheet2DB API using a query. This demonstrates making a DELETE request to the API endpoint. ```javascript fetch(`https://api.sheet2db.com/v1/{connection-id}?id=20`, { method: 'DELETE' }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Update Row using Javascript Source: https://sheet2db.com/docs/update-row Example of updating a row in a Google Sheet using Javascript's fetch API. It shows how to construct a PATCH request with JSON content type and a request body matching spreadsheet column names. ```javascript async function updateRow(connectionId, row, data) { const response = await fetch(`https://api.sheet2db.com/v1/${connectionId}/row/${row}`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); return await response.json(); } // Example usage: // updateRow('your-connection-id', 3, {"name":"Mark","age":18,"id":10}).then(console.log); ``` -------------------------------- ### Delete Row with Query using CURL Source: https://sheet2db.com/docs/delete-query Example CURL command to delete a row from a Google Sheet via the Sheet2DB API using a query. This request targets a specific row by its ID. ```curl curl -XDELETE https://api.sheet2db.com/v1/{connection-id}?id=20 ``` -------------------------------- ### Sheet2DB SDK - Configuration Options Source: https://sheet2db.com/docs/sdks/javascript Details on the configuration options available for initializing the Sheet2DB SDK. ```APIDOC ## Configuration Options ### Sheet2DBOptions - **mode** (`'apikey' | 'connectionId'`) - Authentication mode. Required. - **apiKey** (`string`) - API key for accessing the spreadsheet. Required for `'apikey'` mode. - **spreadsheetId** (`string`) - The ID of the Google spreadsheet. Required for `'apikey'` mode. - **version** (`"v1"`) - API version, always "v1". - **connectionId** (`string`) - Connection ID for accessing the spreadsheet. Required for `'connectionId'` mode. - **basicAuth** (`{ username: string; password: string; }`) - Basic authentication credentials. Optional for `'connectionId'` mode. - **jwtAuth** (`{ bearerToken: string; }`) - JWT authentication token. Optional for `'connectionId'` mode. - **fetchFn** (`typeof fetch`) - Custom fetch function. Optional. ``` -------------------------------- ### Sheet2DB SDK - Import and Initialize Source: https://sheet2db.com/docs/sdks/javascript How to import and initialize the Sheet2DB SDK with different authentication modes. ```APIDOC ## Usage ### Import and Initialize ```javascript import { Sheet2DB, Sheet2DBOptions } from '@sheet2db/sdk'; // API Key authentication const optionsApiKey = { mode: 'apikey', apiKey: 'your-api-key', spreadsheetId: 'your-spreadsheet-id', version: 'v1' }; const sheet2dbApiKey = new Sheet2DB(optionsApiKey); // Connection ID authentication const optionsConnectionId = { mode: 'connectionId', connectionId: 'your-connection-id', version: 'v1' }; const sheet2dbConnectionId = new Sheet2DB(optionsConnectionId); ``` ``` -------------------------------- ### Initialize Sheet2DB SDK (API Key Mode) Source: https://sheet2db.com/docs/sdks/javascript Initializes the Sheet2DB SDK using API key authentication. Requires an API key and spreadsheet ID. ```typescript import { Sheet2DB,Sheet2DBOptions } from '@sheet2db/sdk'; const options = { mode: 'apikey', apiKey: 'your-api-key', spreadsheetId: 'your-spreadsheet-id', version: 'v1' }; const sheet2db = new Sheet2DB(options); ``` -------------------------------- ### Environment-Specific Fetch Implementation in JavaScript Source: https://sheet2db.com/docs/sdks/javascript Automatically detects the execution environment (browser or Node.js) to use the appropriate `fetch` implementation. This ensures compatibility across different platforms by conditionally assigning `window.fetch` or a Node.js compatible fetch. ```javascript let fetchFunction: typeof fetch; if (typeof window !== 'undefined' && typeof window.fetch !== 'undefined') { fetchFunction = window.fetch.bind(window); } else { fetchFunction = async (...args) => { const fetch = global.fetch; return fetch(...args); }; } ``` -------------------------------- ### Initialize Sheet2DB SDK (Connection ID Mode) Source: https://sheet2db.com/docs/sdks/javascript Initializes the Sheet2DB SDK using connection ID authentication. Requires a connection ID. ```typescript import { Sheet2DB,Sheet2DBOptions } from '@sheet2db/sdk'; const options = { mode: 'connectionId', connectionId: 'your-connection-id', version: 'v1' }; const sheet2db = new Sheet2DB(options); ``` -------------------------------- ### Create a New Sheet in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Creates a new, empty sheet within the spreadsheet. An optional title can be provided for the new sheet. The function returns a promise to manage the creation process. ```javascript sheet2db.CreateSheet({ title: 'NewSheet' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### Sheet2DB SDK - Range Method Source: https://sheet2db.com/docs/sdks/javascript Fetches data from a specific range within the spreadsheet using A1 notation. ```APIDOC ### Range Gets a range of values from the spreadsheet. #### Parameters - **range** (`string`) - Required. The range to fetch, in A1 notation. #### Example ```javascript sheet2db.Range({ range: 'A1:B2' }) .then(range => console.log(range)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Generic Error Handling with Promises in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Demonstrates the standard error handling mechanism for Sheet2DB methods. All operations return promises that either resolve with the data on success or reject with an error object, allowing for centralized try-catch-like logic using `.then()` and `.catch()`. ```javascript sheet2db.ReadContent() .then(data => console.log(data)) .catch(error => console.error(error)); ``` -------------------------------- ### Sheet2DB SDK - ReadContent Method Source: https://sheet2db.com/docs/sdks/javascript Fetches content from the spreadsheet with various filtering and formatting options. ```APIDOC ## Methods ### ReadContent Fetches content from the spreadsheet. #### Parameters - **limit** (`number`) - Optional. Maximum number of records to return. - **offset** (`number`) - Optional. Number of records to skip before starting to return records. - **sheet** (`string`) - Optional. The name of the sheet to read from. - **format** (`'records' | 'dict' | 'series' | 'split' | 'index' | 'raw'`) - Optional. The format of the returned data. - **cast_numbers** (`string`) - Optional. Cast numbers to specified type. - **value_render** (`'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA'`) - Optional. The value render option. #### Example ```javascript sheet2db.ReadContent({ sheet: 'Sheet1', limit: 10 }) .then(data => console.log(data)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### CreateSheet API Source: https://sheet2db.com/docs/sdks/javascript Creates a new sheet in the spreadsheet. An optional title can be provided for the new sheet. ```APIDOC ## POST /websites/sheet2db/createSheet ### Description Creates a new sheet in the spreadsheet. An optional title can be provided for the new sheet. ### Method POST ### Endpoint /websites/sheet2db/createSheet ### Parameters #### Request Body - **title** (string) - Optional - The title of the new sheet. ### Request Example ```json { "title": "NewSheet" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **sheetName** (string) - The name of the newly created sheet. #### Response Example ```json { "status": "success", "sheetName": "NewSheet" } ``` ``` -------------------------------- ### Create Sheet API Source: https://sheet2db.com/docs/create-sheet Creates a new sheet (Tab) in your spreadsheet. You can optionally provide a title for the new sheet and copy headers from an existing sheet. ```APIDOC ## POST /v1/{connection-id}/sheet ### Description Creates a new sheet (Tab) in your spreadsheet. You can optionally provide a title for the new sheet and copy headers from an existing sheet. ### Method POST ### Endpoint `/v1/{connection-id}/sheet` ### Parameters #### Query Parameters - **title** (string) - Optional - Name of the new sheet - **copy_headers_from** (string) - Optional - Specifies the name of an existing sheet within the same spreadsheet. The header (first row) from this sheet will be copied to the newly created sheet. #### Request Body Content type: `application/json` This is optional. You can pass an array of string or number to create the first row of your new sheet. ### Request Example ```json [ "Student Name", "Major", "Age" ] ``` ### Response #### Success Response (200) - **properties** (object) - Contains details about the created sheet. - **sheetId** (number) - The unique identifier for the sheet. - **title** (string) - The title of the created sheet. - **index** (number) - The index of the sheet within the spreadsheet. - **sheetType** (string) - The type of the sheet (e.g., "GRID"). - **gridProperties** (object) - Properties related to the grid layout of the sheet. - **rowCount** (number) - The number of rows in the sheet. - **columnCount** (number) - The number of columns in the sheet. #### Response Example ```json { "properties": { "sheetId": 73228599, "title": "Sheet2", "index": 1, "sheetType": "GRID", "gridProperties": { "rowCount": 1000, "columnCount": 26 } } } ``` ``` -------------------------------- ### Create Sheet using Javascript Source: https://sheet2db.com/docs/create-sheet This snippet shows how to create a new sheet in a spreadsheet using the Sheet2DB API with Javascript. It utilizes the Fetch API to send a POST request, including a JSON body for the first row and query parameters for the sheet title. ```javascript const connectionId = '{connection-id}'; const sheetTitle = 'Sheet2'; const firstRowData = ['Student Name', 'Major', 'Age']; fetch(`https://api.sheet2db.com/v1/${connectionId}/sheet?title=${sheetTitle}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(firstRowData) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Sheet2DB Shortcode for Data Display Source: https://sheet2db.com/docs/wordpress-plugin This shortcode fetches data from a Google Spreadsheet via a Sheet2DB API URL and displays it using provided HTML templates. It allows dynamic content insertion using column names enclosed in double braces. Ensure the URL is correct and column names match your spreadsheet. ```html [sheet2db url="https://api.sheet2db.com/v1/608ae724-5285-42fd-a1d9-2e9fad3b22ee?sheet=Products"]

{{Name}}

{{Price}}

[/sheet2db] ``` -------------------------------- ### Sheet2DB SDK - Insert Method Source: https://sheet2db.com/docs/sdks/javascript Inserts new data into a specified sheet. ```APIDOC ### Insert Inserts data into the spreadsheet. #### Parameters - **data** (`Record | Record[]`) - Required. The data to insert. - **sheet** (`string`) - Optional. The name of the sheet to insert data into. #### Example ```javascript sheet2db.Insert({ data: { name: 'John', age: 30 }, sheet: 'Sheet1' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Sheet2DB SDK - Keys Method Source: https://sheet2db.com/docs/sdks/javascript Retrieves the keys (column headers) from a specified sheet. ```APIDOC ### Keys Gets the keys of the spreadsheet. #### Parameters - **sheet** (`string`) - Optional. The name of the sheet to get keys from. #### Example ```javascript sheet2db.Keys({ sheet: 'Sheet1' }) .then(keys => console.log(keys)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Create Sheet using CURL Source: https://sheet2db.com/docs/create-sheet This snippet demonstrates how to create a new sheet with a specified title and optional header copying using a CURL command. It sends a POST request to the Sheet2DB API endpoint with a JSON array for the first row. ```shell curl -XPOST -H "Content-type: application/json" -d '["Student Name","Major","Age"]' 'https://api.sheet2db.com/v1/{connection-id}/sheet?title=Sheet2' ``` -------------------------------- ### Fetch Public Spreadsheet Data using CURL and API Key Source: https://sheet2db.com/docs/public-spreadsheet This snippet demonstrates how to retrieve data from a public Google Spreadsheet using a CURL command. It requires your API Key and the Spreadsheet ID. The output format is set to 'records' with a limit of 10 items. ```shell curl -XGET 'https://api.sheet2db.com/v1/{apiKey}?__id=1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms&format=records&limit=10' ``` -------------------------------- ### Sheet2DB Table Shortcode for Data Display Source: https://sheet2db.com/docs/wordpress-plugin The `sheet2db_table` shortcode displays Google Sheet data in a structured HTML table. It supports various customization options for appearance, sorting, searching, and pagination. Specify the connection `id` and optionally other attributes to control the table's behavior and look. ```html [sheet2db_table id="608ae724-5285-42fd-a1d9-2e9fad3b22ee" title="Product List" table_bg="bg-white" header_bg="bg-gray-200" dark_mode="false" font_family="Arial, sans-serif" sortable_columns="Name,Price" striped="true" enable_search="true" limit="10" offset="0" sheet="Products"] ``` -------------------------------- ### Sheet2DB SDK - UpdateWithQuery Method Source: https://sheet2db.com/docs/sdks/javascript Updates multiple rows in a specified sheet based on a query. ```APIDOC ### UpdateWithQuery Updates rows based on a query. (Detailed parameters and example for this method are not provided in the input text.) ``` -------------------------------- ### Batch Update using CURL Source: https://sheet2db.com/docs/update-batch This snippet demonstrates how to perform a batch update on a Google Sheet using the CURL command-line tool. It specifies the API endpoint, HTTP method (PATCH), content type, and the JSON payload containing the update queries and records. ```shell curl -XPATCH https://api.sheet2db.com/v1/{connection-id}/batch \ -H "Content-Type:application/json" \ -d '[{query:"id=name",record:{"name":"Mark","age":18}}]' ``` -------------------------------- ### Sheet2DB SDK - Search Method Source: https://sheet2db.com/docs/sdks/javascript Searches for records within a specified sheet based on a query. ```APIDOC ### Search Searches for records in the spreadsheet. #### Parameters - **sheet** (`string`) - Optional. The name of the sheet to search in. - **or** (`boolean`) - Optional. If true, uses OR logic for the search. - **query** (`string`) - Required. The search query. #### Example ```javascript sheet2db.Search({ query: 'name=John', sheet: 'Sheet1' }) .then(records => console.log(records)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Sheet2DB API Permissions Source: https://sheet2db.com/docs/security Sheet2DB API provides several permission levels to control access to your data. Granting the minimum necessary permissions is recommended for enhanced security. ```APIDOC ## Sheet2DB API Permissions ### Description Sheet2DB API supports various permission levels to control access to your spreadsheet data. It is recommended to grant only the minimum required permissions for your application's functionality. ### Permissions Overview - **Read**: Allows `GET` requests to eligible endpoints (excluding search endpoints). - **Search**: Allows `GET` requests to search endpoints. - **Update**: Allows `POST` and `PATCH` requests to all eligible endpoints. - **DELETE**: Allows `DELETE` requests to all eligible endpoints. Accessing an unauthorized endpoint will result in a `403 Forbidden` error. ``` -------------------------------- ### Perform Batch Updates in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Updates multiple records efficiently using batch processing. It accepts an array of batch objects, each containing a query to identify rows and the record data for the update, along with an optional sheet name. This method returns a promise for handling the asynchronous operation. ```javascript sheet2db.BatchUpdate({ batches: [{ query: 'name=John', record: { age: 33 } }], sheet: 'Sheet1' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### BatchUpdate API Source: https://sheet2db.com/docs/sdks/javascript Updates multiple records in batches within a specified sheet. Each batch item includes a query and the record data for the update. ```APIDOC ## POST /websites/sheet2db/batchUpdate ### Description Updates multiple records in batches within a specified sheet. Each batch item includes a query and the record data for the update. ### Method POST ### Endpoint /websites/sheet2db/batchUpdate ### Parameters #### Query Parameters - **sheet** (string) - Optional - The name of the sheet to update data in. #### Request Body - **batches** ({ query: string, record: Record }[]) - Required - The batch update data, where each item contains a query and the record to update. ### Request Example ```json { "sheet": "Sheet1", "batches": [ { "query": "name=John", "record": { "age": 33 } } ] } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Sheet2DB SDK - Title Method Source: https://sheet2db.com/docs/sdks/javascript Retrieves the title of the spreadsheet. ```APIDOC ### Title Gets the title of the spreadsheet. #### Example ```javascript sheet2db.Title() .then(title => console.log(title)) .catch(error => console.error(error)); ``` ``` -------------------------------- ### Batch Update using Javascript Source: https://sheet2db.com/docs/update-batch This snippet shows how to implement a batch update for a Google Sheet using Javascript. It utilizes the `fetch` API to send a PATCH request to the Sheet2DB API endpoint with a JSON payload detailing the update operations. ```javascript fetch('https://api.sheet2db.com/v1/{connection-id}/batch', { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify([ { query: 'id=name', record: { 'name': 'Mark', 'age': 18 } } ]) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Sheet Selection Source: https://sheet2db.com/docs/sheet-selection Allows you to select a specific sheet within your Sheet2DB connection. If no sheet is specified, the first sheet is selected by default. An error is returned if the specified sheet is not found. ```APIDOC ## GET /v1/ ### Description Select a specific sheet from your Sheet2DB connection. If the `sheet` query parameter is not provided, the first sheet in the connection is used by default. A `400 Bad Request` error will be returned if the specified sheet does not exist. ### Method GET ### Endpoint `https://api.sheet2db.com/v1/` ### Query Parameters - **sheet** (string) - Optional - The name of the sheet to select (case-sensitive). ### Request Example ```json { "example": "GET https://api.sheet2db.com/v1/?sheet=sheet1" } ``` ### Response #### Success Response (200) - **data** (array) - The data from the selected sheet. #### Response Example ```json { "example": { "data": [ { "column1": "value1", "column2": "value2" }, { "column1": "value3", "column2": "value4" } ] } } ``` ``` -------------------------------- ### Embed Google Sheet as Table using Iframe Source: https://sheet2db.com/docs/embed-table This snippet shows how to embed a Google Sheet as a table into your website using an iframe. The `src` attribute includes the Sheet2DB URL with a connection ID. Various parameters can be appended to the URL to customize the table's display and functionality, such as styling, search, and image handling. ```html ``` -------------------------------- ### UpdateWithQuery API Source: https://sheet2db.com/docs/sdks/javascript Updates existing rows in a specified sheet based on a query. Allows for partial updates of records. ```APIDOC ## POST /websites/sheet2db/update ### Description Updates existing rows in a specified sheet based on a query. Allows for partial updates of records. ### Method POST ### Endpoint /websites/sheet2db/update ### Parameters #### Query Parameters - **sheet** (string) - Optional - The name of the sheet to update data in. #### Request Body - **query** (string) - Required - The query to identify rows to update. - **data** (Record) - Required - The data to update. ### Request Example ```json { "sheet": "Sheet1", "query": "name=John", "data": { "age": 32 } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Insert Data into Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Inserts new data into a specified sheet in Google Sheets. Can insert a single record or an array of records. Handles potential errors during the insert operation. ```typescript sheet2db.Insert({ data: { name: 'John', age: 30 }, sheet: 'Sheet1' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### Read Content from Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Reads content from a specified sheet in Google Sheets. Supports limiting results, skipping records, and formatting output. Handles potential errors during the fetch operation. ```typescript sheet2db.ReadContent({ sheet: 'Sheet1', limit: 10 }) .then(data => console.log(data)) .catch(error => console.error(error)); ``` -------------------------------- ### Update Rows with Query in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Updates specific rows in a sheet based on a provided query. It takes the query string, the data to update, and an optional sheet name as input. The function returns a promise that resolves with the API response or rejects with an error. ```javascript sheet2db.UpdateWithQuery({ query: 'name=John', data: { age: 32 }, sheet: 'Sheet1' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### Search Records in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Searches for records within a specified sheet based on a query. Supports OR logic for multiple conditions. Handles potential errors during the search operation. ```typescript sheet2db.Search({ query: 'name=John', sheet: 'Sheet1' }) .then(records => console.log(records)) .catch(error => console.error(error)); ``` -------------------------------- ### Search OR API Source: https://sheet2db.com/docs/search Allows searching for rows where at least one of the specified conditions is met. This is an alternative to the standard search endpoint for OR logic. ```APIDOC ## GET /v1/{connection-id}/serach_or/{sheet} ### Description Returns an array of rows where ANY of the specified conditions are met. This endpoint is used when you want a row to be included in the result if at least one condition is satisfied. ### Method GET ### Endpoint `https://api.sheet2db.com/v1/{connection-id}/serach_or/{sheet}` ### Parameters #### Path Parameters - **sheet** (string) - Optional - Specify the name of the sheet (tab) you wish to select within your Google Spreadsheet. #### Query Parameters (Same query parameters as the `Search API` apply, including `__limit`, `__offset`, `__columns`, `__cast_numbers`, `__sort`, `__sort_method`, `__sort_date_format`, wildcards, and relational operators.) ### Request Example ```bash curl -XGET 'https://api.sheet2db.com/v1/{connection-id}/serach_or?status=active,pending&age>20' ``` ### Response #### Success Response (200) - **Array of Objects** - Each object represents a row matching at least one of the search criteria. #### Response Example ```json [ { "id": "1", "name": "Alice", "age": "25", "status": "active" }, { "id": "3", "name": "Bob", "age": "30", "status": "pending" } ] ``` ``` -------------------------------- ### Batch Update Source: https://sheet2db.com/docs/update-batch Perform batch updates on a Google Sheet by providing an array of update operations. Each operation includes a query to identify rows and a record containing the data to update. ```APIDOC ## PATCH /v1/{connection-id}/batch/{sheet}? ### Description Update multiple rows in a Google Sheet using an array of query and record objects. ### Method PATCH ### Endpoint `https://api.sheet2db.com/v1/{connection-id}/batch/{sheet}` ### Parameters #### Path Parameters - **sheet** (string) - Optional - Specify the name of the sheet (tab) you wish to select within your Google Spreadsheet. #### Request Body Content type: `application/json` or `application/x-www-form-urlencoded` Must be an array with objects containing `query` & `record`. - **query** (string) - Used to find all the rows that need to be updated. - **record** (object) - Designed for insertion into a spreadsheet. Should contain keys corresponding to the column names of the spreadsheet. ### Request Example ```json [ { "query": "id=name", "record": { "name": "Mark", "age": 18 } } ] ``` ### Response #### Success Response (200) - **updated** (integer) - The number of rows updated. #### Response Example ```json { "updated": 1 } ``` ``` -------------------------------- ### Search Rows with Conditions (CURL) Source: https://sheet2db.com/docs/search Demonstrates how to perform a search query using cURL to retrieve rows from a Google Sheet that meet specific criteria, such as name and age. ```shell curl -XGET 'https://api.sheet2db.com/v1/{connection-id}/search?name=John&age>20' ``` -------------------------------- ### Clear All Data from a Sheet in Sheet2DB Source: https://sheet2db.com/docs/sdks/javascript Removes all data content from a specified sheet. The function requires the sheet name as a parameter and returns a promise to handle the asynchronous clearing operation. ```javascript sheet2db.Clear({ sheet: 'Sheet1' }) .then(response => console.log(response)) .catch(error => console.error(error)); ``` -------------------------------- ### Sheet2DB API Authentication Source: https://sheet2db.com/docs/security Sheet2DB API offers two primary authentication methods: Basic Authentication and JWT Authentication, to secure access to your spreadsheet data. ```APIDOC ## Sheet2DB API Authentication ### Description Sheet2DB API supports two authentication methods to secure access to your spreadsheet data: Basic Authentication and JWT Authentication. ### Basic Authentication - **Method**: Uses username and password for HTTP request authentication. - **Configuration**: You can define your own username and password. ### JWT Authentication - **Method**: Uses JSON Web Tokens (JWT) for authentication. - **Process**: You can sign a token with your preferred encryption key and share the verification key with Sheet2DB to confirm token authenticity. - **Supported Algorithms**: - `HS256` - `RS256` ```