CodaPHP is a library that makes it easy to use data from Coda docs your in web projects by using the Coda API. Use on your own risk.
Easily use all available API calls with one library including
- List all documents
- Read data from tables, formulas and controls
- Add/modify rows
- and a lot more
→ Get 10$ discount on Coda paid plans when signing up with this link
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);
Let's assume you have the table 'Products' in your Coda doc:
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';
}
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.
Generate your token in the Coda profile settings. Notice: Everyone with this token has full access to all your docs!
The method names are inspired by the wording of the official Coda API documentation and are listed below.
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.
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.
$coda = new CodaPHP('<YOUR API TOKEN>'); // Create instance of CodaPHP
$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
$coda->listPages('<DOC ID>'); // List all sections in a doc
$coda->getPage('<DOC ID>', '<PAGE NAME OR ID>'); // Get a section in a doc
$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
Since Coda API Version 1.0.0 there are no seperate view methods. All view operations can be done via the table methods.
$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
$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
$coda->whoAmI(); // Get information about the current account
$coda->resolveLink('<DOC URL>'); // Resolves a link
$coda->getMutationStatus('<Request Id>'); // Resolves a link
- Update to API version 1.0.0.
- Breaking changes:
- Sections & Folders have been replaced by pages
- Removed 'view' methods. You can access views via table methods.
- New features:
- Added mutation status method You can read more about API version 1.0.0 here
- Updated to API version 0.2.4-beta. New features:
- Pushing buttons inside of tables & views
- Getting and interacting with views
- Creating docs in folders
- Ability to disable parsing of cell values
- Fixed an issue with using queries in listRows (Thanks to Al Chen from Coda for mentioning this)
- Fixed an issue regarding table names with special characters (Thanks to Oleg from Coda for mentioning this)
- Initial version based on v0.1.1-beta of Coda API