CodaPHP: A library to easily use Coda API

#1

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.

10 Likes

#2

Wow this is awesome, nice work @Daniel_Stieber !

2 Likes

#3

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

1 Like

#4

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:

1 Like

#5

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

1 Like

#6

@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?

0 Likes

#7

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

0 Likes

#8

@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

0 Likes

#9

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

0 Likes

#10

@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

Coda Docs updating referenced Google Sheets
#11

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

#12

Thanks @Daniel_Stieber for making the fix!

0 Likes

#13

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

#14

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

0 Likes

#15

@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