CodaPHP: A library to easily use Coda API

I created a PHP library that helps using the Coda API in web projects fast and easy.

You can install and use it with composer and it covers all functionalities of the current API version (0.1.1-beta).

You can find it on https://github.com/danielstieber/CodaPHP

Since Coda and the API is in beta, you can also see this library as in beta. Use it on your own risk.

An inspiration what you could do with it:

  • Read data from cells and use it on your site
    (sync your menu for your restaurant website, show/count your current projects, show how many available items are in stock, show office hours, team membersā€¦)
  • Fill a table with data
    (create a web form to submit data into coda, count events on your site)
  • Use coda controls to control your website
    (create a ā€˜mood-sliderā€™ next to your to-do list that shows your motivation and then change the colors/images of your website based on your acutal mood)

A basic example how to get data from a cell:

Click to see the table in Coda

03

$coda = new CodaPHP('<API TOKEN>'); // Create a new instance
$result = $coda->getRow('<DOC ID>', 'Products', 'Goatmilk'); // Get the row with name 'Goatmilk'
echo $result['values']['Price'];  // Output Price value of this row

This will output 14.9 on the page.

More examples and a documentation to all functions is provided in the readme on Github.

Updates and contribution

First of all thanks to @oleg for your early feedback!

Iā€™ll try to keep the library up to date whenever new API features are released.

If your find bugs, have problems implementing it or if have some suggestions, donā€™t hesitate to contact me :slight_smile:
Also, it would be cool if you share your results if you implement it somewhere.

24 Likes

Wow this is awesome, nice work @Daniel_Stieber !

3 Likes

This is amazing @Daniel_Stieber. Havenā€™t touched PHP in ages but will try playing around with your library!

2 Likes

Thanks for your contribution, @Daniel_Stieber! Weā€™d linked to your repository on our API docs under a new ā€œThird-party librariesā€ section. If anyone else has a library for our API theyā€™d like added there, get in touch. :slight_smile:

3 Likes

Thanks for creating this and sharing @Daniel_Stieber - shared it with the team internally!

2 Likes

@Daniel_Stieber

Thanks for adding this, Iā€™m trying to use an API for the first time and Iā€™m getting and error.

Fatal error : Uncaught Error: Class ā€˜CodaPHPā€™ not found in /Users/juan/Documents/Sites/coda-api/index.php:235 Stack trace: #0 /Users/juan/.composer/vendor/laravel/valet/server.php(158): require() #1 {main} thrown in /Users/juan/Documents/Sites/coda-api/index.php

So far Iā€™ve only installed it through composer and added the following to my index.php file:

require ā€˜./vendor/autoload.phpā€™; $coda = new CodaPHP(ā€˜<YOUR API TOKEN>ā€™);
// List all your docs
$result = $coda->listDocs(); var_dump($result);

Any ideas what Iā€™m doing wrong?

Hey @Juanmata,
thanks for reaching out. This is actually an error in the documentation, thanks for mentioning that! Have to fix this.

Please use
$coda = new CodaPHP\CodaPHP('<YOUR API TOKEN>');
instead of
$coda = new CodaPHP('<YOUR API TOKEN>');
and let me know how everything works!

Best,
Daniel

1 Like

@Daniel_Stieber

Hi thanks for that, that now works.

Are you still playing about with this?

Are you able to develop your demo a bit further maybe using a simple form with a submit button?

Iā€™m keen to use my own forms so I can get a simple design layout that matches my site and also having an option to gather the data in an A4 format so I can email / post invoices. I just need a few demoā€™s to get my started so I can work out how itā€™s done.

Iā€™m taking it that the API key will also be visible?

When I was looking at APIs when I was using Airtable, I believe they were talking about a proxy to not only hide the API key but also combat Airtableā€™s five requests per second per base rate limit. Does Coda have a limit like this?

Thanks

Hey @Juanmata, glad that it works now!

I will enhance CodaPHP when new features in the Coda API will be available or bugs are coming up. Currently it should cover all available API methods.

The API Key is visible to all people who have access to your server. Since PHP is a server-sided programming language, it only passes results to the browser/user, no plain code. So there should not be any way for a website visitor to get your API Key. I guess this is as secure as every ā€œconfig.phpā€ with mysql login data etc. But yes, everyone with ftp server access can get the API Key and has full access to all your docs, so be careful with it.

Regarding rate limit: The docs say, that there is a ā€œreasonable rate limitā€. You can find more about this here.

Do you mean a simple online form that creates rows in a coda table?

Best

1 Like

@Juanmata I built a simple website about FODMAPs here using @Daniel_Stieberā€™s library. Source is here.

@Daniel_Stieber Iā€™m curious how you sort and filter data once you receive the response? For instance, I wanted to filter the returned rows using the listRows function but couldnā€™t find the right syntax to use the query parameter from the List rows endpoint in the API. I saw in your documentation for ways to use the query parameter to search docs, but the query parameter in the List rows endpoint needs a key and value. I thought ['query' => array('Food Group' => 'Grains/Starches')] might work in this scenario but it didnā€™t.

2 Likes

Hey @Al_Chen_Coda,
thanks for pointing that out.

listRows() was not handling the query right!
I fixed that issue in the current development version: https://github.com/danielstieber/CodaPHP/tree/develop
I already tried it with your code, and it worked fine. You can even shorten the array syntax:
$rows = $coda->listRows($docID, $tableID, ['query' => ['Food Group' => 'Grains/Starches']]);
Maybe you can give it a shot.

Before I release 0.0.3 with the fix, I have one question to @oleg or someone of the API team:

Is it possible to add multiple filters in a query in the listRows method and how would a request look like? (like where ab=xy and cd=wy)
I was not able to do it or to find out the right syntax. CodaPHP currently only translates one query, but if the API can do it, Iā€™d like to implement it too.

Best,
Daniel

2 Likes

Thanks @Daniel_Stieber for making the fix!

Iā€™ve released version 0.0.3

The query in ā€œlistRowsā€ is now working and Iā€™ve added a short example in the readme under ā€œhandling table dataā€

You can update via composer or get it from https://github.com/danielstieber/CodaPHP

1 Like

@Daniel_Stieber I checked with @oleg and right now the query parameter can only have one filter at the moment :neutral_face:

@Al_Chen_Coda ok thanks for the update!

I guess in most scenarios it would make sense to fetch (and maybe even cache) all rows and filter it down with php locally. so no big deal until there is no ā€œfree plan with limited rowsā€ :slight_smile:

1 Like

Thank you so much @Daniel_Stieber for this PHP Library. Used it as a base for a GravityForms addon to push form entries to a specific coda table

3 Likes

Very nice! Love that you were able to use it in a really useful project!

Do you have some feedback on the library? Like, was something not you expected it to be, or do you see the need of some more data formatting options or something?

Iā€™ve realized that the API allows you to duplicate docs as well. This is not implemented yet and will be part of a future update.

thanks @Daniel_Stieber. For this project no. but i am working on another Wordpress plugin which will be more involved.
so far its pretty simple and self explanatory. might have some questions for the next project.

1 Like

Thank you, thank you , thank you! This is exactly what I was looking for. I want to use Coda for our companyā€™s intranet, to include dynamic reporting for our employees and was struggling to find a good solution for building web forms to update a Coda table. Thanks again for putting this together and making it publicly available!

2 Likes

You are very welcome :slight_smile: let me know if something isnā€˜t working as expected!