CodaPHP
PHP library to use data from Coda documents in webprojects (via Coda API)
Install / Use
/learn @danielstieber/CodaPHPREADME
CodaPHP
CodaPHP is a library that makes it easy to use data from Coda docs in web projects by using the Coda API.
Easily use all available API calls with one library including
- List all documents
- Read data from tables, formulas and controls
- Add/modify rows
- Manage doc permissions
- and a lot more
→ Get 10$ discount on Coda paid plans when signing up with this link
Quickstart
Installation and basic usage
Install the library through Composer:
php composer.phar require danielstieber/coda-php
and add it to your project:
require './vendor/autoload.php';
$coda = new CodaPHP\CodaPHP('<YOUR API TOKEN>');
// List all your docs
$result = $coda->listDocs();
var_dump($result);
Handling table data
Let's assume you have the table 'Products' in your Coda doc:
Products
| Title ⚑ | Price | Status | |-----------|-------|-------------| | Goatmilk | 14.90 | available ▼ | | Goatmeat | 38.90 | available ▼ |
// Get the price of the goatmilk
$docId = $coda->getDocId('<YOUR DOC URL>');
// Lists only Products with status 'available' (currently only one filter allowed)
$availableProducts = $coda->listRows($docId, 'Products', ['query' => ['status' => 'available']]);
// Show value of one cell
$result = $coda->getRow($docId, 'Products', 'Goatmilk');
var_dump($result['values']['Price']);
// Will show you 'float(14.90)'
// Add the new product 'Goatcheese'
if($coda->insertRows($docId, 'Products', ['Title' => 'Goatcheese', 'Price' => 23.50, 'Status' => 'available'])) {
echo 'Product added';
}
// Change the status of the product 'Goatmilk' to 'sold out'
if($coda->insertRows($docId, 'Products', ['Title' => 'Goatmilk', 'Status' => 'sold out'], ['Title'])) {
echo 'Product updated';
}
Triggering automations
Since May 2022, Coda automations can be triggered via webhooks – and via CodaPHP. To trigger an automation, the automation must be set to "Webhook invoked". To run the automation you need the doc ID an the ID of the automation rule. You can find the rule ID when you click on the 3 dots (kebap menu) above the rule step settings.
// Trigger the automation
$result = $coda->runAutomation('<YOUR DOC ID>', '<THE RULE ID>');
Overview
This is a personal side project. If you have any suggestions, find bugs or want to contribute, don't hesitate to contact me. You can use the offical Coda community to asks questions and reach out as well.
Token
Generate your token in the Coda profile settings. Notice: Everyone with this token has full access to all your docs!
Methods
The method names are inspired by the wording of the official Coda API documentation and are listed below.
Parameters
All parameters can be found in the official Coda API documentation. Just add an associative array with your parameters to selected functions. The parameter useColumnNames is set true by default in all 'row' functions. I list the important ones below.
Response
In case of success, responses are mostly untouched but converted to PHP arrays. Exception is insertRow() function, which provides a boolean true in case of success.
In case of an error, the response includes the statusCode and provided error message, also untouched and converted to an array.
Cache data
Every API call may take a few seconds. It is recommended to store results and only call for new when necessary. The library provides a simple caching mechanic to store received data in a .codaphp_cache folder. This mechanic is optional and needs to be activated. Learn more in the caching instructions
Documentation
$coda = new CodaPHP('<YOUR API TOKEN>'); // Create instance of CodaPHP
Docs
$coda->getDocId('<YOUR DOC URL>'); // Get the id of a doc
$coda->listDocs(); // List all docs you have access to
$coda->listDocs(['query' => 'todo']); // List docs filtered by searchquery 'todo'
$coda->getDoc('<DOC ID>'); // Get a specific doc
$coda->createDoc('My new doc'); // Create a new doc
$coda->createDoc('Copy of my old doc', '<DOC ID>'); // Copy a doc
Pages (former Folders & Sections)
$coda->listPages('<DOC ID>'); // List all sections in a doc
$coda->getPage('<DOC ID>', '<PAGE NAME OR ID>'); // Get a section in a doc
Tables/Views, Columns and Rows
$coda->listTables('<DOC ID>'); // List all tables in a doc
$coda->getTable('<DOC ID>', '<TABLE/VIEW NAME OR ID>'); // Get a table in a doc
$coda->listColumns('<DOC ID>', '<TABLE/VIEW NAME OR ID>'); // List all columns in a table
$coda->getColumn('<DOC ID>', '<TABLE/VIEW NAME OR ID>', '<COLUMN NAME OR ID>'); // Get a column in a table
$coda->listRows('<DOC ID>', '<TABLE/VIEW NAME OR ID>'); // List all row in a table
$coda->insertRows('<DOC ID>', '<TABLE/VIEW NAME OR ID>', [['<COLUMN ID OR NAME>' => '<VALUE>']], ['<KEYCOLUMN>']); // Insert/updates a row in a table
// Examples:
$coda->insertRows('<DOC ID>', 'todos', ['title' => 'Shower']); // Adds one row to 'todo'
$coda->insertRows('<DOC ID>', 'todos', [['title' => 'Wash dishes'], ['title' => 'Clean car']]); // Adds two rows to 'todo'
$coda->insertRows('<DOC ID>', 'todos', [['title' => 'Shower', 'status' => 'done'], ['title' => 'Buy goatcheese']], ['title']); // Updates the status of 'Shower' and inserts a new todo
$coda->updateRow('<DOC ID>', '<TABLE/VIEW NAME OR ID>', '<ROW NAME OR ID>', ['<COLUMN ID OR NAME>' => '<VALUE>']); // Updates a row in a table
$coda->getRow('<DOC ID>', '<TABLE/VIEW NAME OR ID>', '<ROW NAME OR ID>'); // Get a row in a table
$coda->deleteRow('<DOC ID>', '<TABLE/VIEW NAME OR ID>', '<ROW NAME OR ID>'); // Deletes a row in a table
Working with Views
Since Coda API Version 1.0.0 there are no seperate view methods. All view operations can be done via the table methods.
Pushing Buttons
$coda->pushButton('<DOC ID>', '<TABLE/VIEW NAME OR ID>', '<ROW NAME OR ID>', '<COLUMN NAME OR ID'>); // Pushes the button on the given column in a table
Formulas and Controls
$coda->listFormulas('<DOC ID>'); // List all formulas in a doc
$coda->getFormula('<DOC ID>', '<FORMULA NAME OR ID>'); // Get a formula in a doc
$coda->listControls('<DOC ID>'); // List all controls in a doc
$coda->getControl('<DOC ID>', '<CONTROL NAME OR ID>'); //Get a control in a doc
Manage permissions
$coda->listPermissions('<DOC ID>'); // Get information about users & permissions for a doc
$coda->addUser('<DOC ID>', '<EMAIL>'); // Add a user to a doc (default permissions are 'write')
$coda->addUser('<DOC ID>', '<EMAIL>', 'readonly', true); // Add a 'readonly' user and notify via email
$coda->deleteUser('<DOC ID>', '<EMAIL>'); // Removes a user from the doc
$coda->addPermission('<DOC ID>', '<PERMISSION TYPE>', '<PRINCIPAL>', '<NOTIFY>'); // Add a permission to a doc
$coda->deletePermission('<DOC ID>', '<PERMISSION ID>'); // Remove a permission from a doc
$coda->getACLMetadata('<DOC ID>'); // Returns the ACL metadata of a doc
Learn more about permission settings with the API here.
Run automations / trigger webhooks
$coda->runAutomation('<YOUR DOC ID>', '<THE RULE ID>');
Account and other
$coda->whoAmI(); // Get information about the current account
$coda->resolveLink('<DOC URL>'); // Resolves a link
$coda->getMutationStatus('<REQUEST ID>'); // Resolves a link
Analytics
$coda->listDocAnalytics(); // List all docs with analytics data
$coda->listDocAnalytics(['query' => 'Goats', 'sinceDate' => '2022-08-02', 'sinceDate' => '2022-08-04']); // List docs about "Goats" with analytics data between 2nd and 4th of August 2022
// All parameters for all methods can be found in the official API docs: https://coda.io/developers/apis/v1#tag/Analytics/operation/listDocAnalytics
$coda->listPageAnalytics('<DOC ID>'); // List analytics data on page level of given doc
$coda->listPackAnalytics(); // List all packs where user has edit rights with analytics data
$coda->listPackAnalytics(['workspaceId' => 'ws-123Ave']); // List all packs where user has edit rights with analytics data from workspace ws-123Ave
$coda->listPackFormulaAnalytics('<PACK ID'); // List analytisc data on formula level of given pack
$coda->getDocAnalyticsSummery(); // Returns summarized analytics data for available docs.
$coda->getPackAnalyticsSummery(); // Returns summarized analytics data for available packs.
$coda->getAnalyticsUpdatedDay(); // Returns days based on Pacific Standard Time when analytics were last updated. Usually 1 day ago PST.
Caching
The library can cache API requests in JSON files. If caching is activated, the library tries to create a .codaphp_cache folder in your project root. If it can't create or find the folder, it will deactivate caching. You can also create the folder on your own and set CHMOD so the library can read & write files in it. Only doc data & content will be cached, no permissions, links or mutation status!
$coda = new CodaPHP('<YOUR API TOKEN>', '<ACTIVATE CACHE>', '<EXPIRY TIME IN SECONDS>'); // Instance creation with otptional caching & expiry time
$coda = new CodaPHP('<YOUR API TOKEN>', true); // Instance
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
