CodaPHP: A library to easily use Coda API

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!

Released version 0.0.4
All features from API version 0.2.4 can be used now with the library.

1 Like

Can backup all sections and tables by CodaPHP ?

You can get and modify the table data with the API via PHP e.g. in a webpage project or tool. So you could backup some of the result data but you can not backup raw formulas, create sections, controls or automations.

If you want to back up a whole doc, you can just duplicate the doc file in GDrive I guess :thinking:

Hi Daniel,

This is great. I’ve just discovered Coda and am trying to update tables via a small bit of php. I am afriad my php is based on searches and trail and effort.

Is there anyway in referencing the last row written to a table? I can see it in the listRows var_dump. As in [0] position in the array. However I can not work out how to get to it.

My table is a simple timestamp that creates a row when a IoT Amp monitor trips. It then trips again when the power goes off. This should result in one row wiht time on and time off. I can do the add bit but not the update last record written.

No worries if you can’t help and thanks for excellent CodaPHP.

Francis

1 Like