Official PHP SDK for the SheetToJSON RapidAPI. Turn Google Sheets into a secure CRUD backend.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/sheettojson-api/client

dev-main 2026-02-21 21:38 UTC

This package is auto-updated.

Last update: 2026-02-21 21:40:34 UTC


README

Official PHP SDK for the SheetToJSON RapidAPI. Turn any Google Spreadsheet into a secure, blazing-fast REST API with built-in S3 caching and smart querying.

Zero external dependencies. This package uses native PHP cURL for maximum performance and compatibility.

Requirements

  • PHP >= 7.4
  • cURL extension enabled
  • JSON extension enabled

Installation

Install the package via Composer:

composer require sheettojson-api/client

Initialization

Require the Composer autoloader and initialize the SDK with your RapidAPI key.

<?php

require_once 'vendor/autoload.php';

use SheetToJSON\API\SheetToJSON;

// Initialize with your RapidAPI Key
$db = new SheetToJSON('YOUR_RAPIDAPI_KEY');

$SPREADSHEET_ID = '1BxiMVs0XRA5nFMdkvBdBZjgmZ_xyz123'; // Found in your Google Sheet URL
$SHEET_NAME = 'Products'; // The exact name of the tab

Usage Examples

All methods throw an Exception if the API request fails. It is highly recommended to wrap your calls in a try...catch block.

1. Register your Spreadsheet

You must link a spreadsheet to your RapidAPI account once before using the CRUD operations. Don't forget to share your sheet with the service account email first!

try {
    $response = $db->register($SPREADSHEET_ID);
    echo $response['message'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

2. Read and Filter Data (GET)

Retrieve rows with built-in pagination, sorting, and advanced filtering.

try {
    $response = $db->get($SPREADSHEET_ID, $SHEET_NAME, [
        'limit' => 10,           // Max 1000, default 100
        'page' => 1,             
        'price' => 'gt:50',      // Advanced filter: Price Greater Than 50
        'category' => 'lk:tech', // Advanced filter: Category Contains (Like) "tech"
        'sort' => 'price:desc'   // Sort by price descending
    ]);

    echo "Found " . $response['meta']['returned_rows'] . " rows.\n";
    print_r($response['data']);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

3. Insert Data (POST)

Add new rows to the bottom of your sheet. You can pass a single associative array or an array of arrays for batch insertion.

try {
    $newProducts = [
        [
            'id' => 105, 
            'name' => 'Wireless Mouse', 
            'price' => 25.99, 
            'stock' => 150
        ],
        [
            'id' => 106, 
            'name' => 'Mechanical Keyboard', 
            'price' => 89.00, 
            'stock' => 40
        ]
    ];

    $response = $db->insert($SPREADSHEET_ID, $SHEET_NAME, $newProducts);
    echo $response['message']; // "2 row(s) successfully inserted."
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

4. Update Data (PATCH)

Update specific fields of an existing row. Provide the column name (lookup_key) and the value (lookup_value) to find the exact row to update.

try {
    // Find the row where 'id' equals 105, and update its price and stock
    $response = $db->update($SPREADSHEET_ID, $SHEET_NAME, 'id', 105, [
        'price' => 19.99,
        'stock' => 140
    ]);

    print_r($response['updated_data']);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

5. Delete Data (DELETE)

Delete a row from your sheet using the lookup system.

try {
    // Find and delete the row where 'id' equals 105
    $response = $db->delete($SPREADSHEET_ID, $SHEET_NAME, 'id', 105);
    echo $response['message'];
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

License

MIT