Google Sheets JSON with PHP - SheetDB - Google Sheets REST API

How to get data from Google Spreadsheet to your PHP application?

There are several ways to get API data to your PHP application. If you use the composer in your project, we recommend using SheetDB PHP library or Guzzle. If not you can use vanilla PHP functions like file_get_contents to get the job done. Let's check both cases.

SheetDB PHP Library

The description how to use it is on the GitHub page, but in short. First you need to install library, type in your terminal:

composer require sheetdb/sheetdb-php

Than import it and use like in GitHub page. Here are some examples:

use SheetDB\SheetDB;

$sheetdb = new SheetDB('58f61be4dda40');

// returns all spreadsheets data
$response = $sheetdb->get();

// returns when name="Steve" AND age=22
$response = $sheetdb->search(['name'=>'Steve','age'=>'22']);

// returns when name="Steve" OR age=19
$response = $sheetdb->searchOr(['name'=>'Steve','age'=>'19']);

// insert one row

// insert array of rows

// update a row for name="Chris"

// will delete all rows with name = "Chris"

PHP without any libraries

If you are not using the composer, you can use file_get_contents like so:

function requestSheetdb($url, $method = 'GET', $data = []) {

  $options = array(
    'http' => array(
      'header'  => 'Content-type: application/x-www-form-urlencoded',
      'method'  => strtoupper($method),
      'content' => http_build_query([
        'data' => $data

  try {
    $raw = @file_get_contents($url, false, stream_context_create($options));
    $result = json_decode($raw);
  } catch (Exception $e) {
    return false;

  return $result;

// returns all spreadsheets data
$content = requestSheetdb('');

// returns when name="Steve" AND age=22
$content = requestSheetdb('');

// insert one row
$content = requestSheetdb('', 'POST', ['name'=>'Mark','age'=>'35']);

// etc.

Have question?

If you have any questions feel free to ask us via chat or .