Hey! I’ve gotten everything working with the API as far as fetching data, but I’m running into an issue with getting data that’s nested inside that data.
The Coda API will allow me to pull in a table, separated by rows. Ultimately, my goal is to have each row on its own page, with the cell data from that row populating the fields on that page.
The actual cell data, though, is inside an object (‘values’) that’s nested inside the object for each row. The row data itself pulls in the rows nested under the object ‘items’:
But when I try to do it for the individual pages, it always shows the ‘values’ data for the first row. I’ve checked, and the slug is updating appropriately (i.e. the slug for “Test Name 2” is the right one for that page), but the data on the page itself is still the data from “Test Name 1”.
I selected my Coda data as the source on a page level for the single-row page, but I can’t do an iterable because I’m not trying to show all of the data (just the data for that page), and I’m not sure how else to drill down into the nested object.
Is there another way to access the nested object for each of the original objects, either with another API key or with a function in the builder? Thanks in advance!
Okay, I set up two different GET requests, one that lists the rows in the table, and one that gets only the first row using that row’s id as part of the endpoint. What’s next?
Just to mention that when using “Variable” feature in REST API, the data get’s stored in variable, but every time you refresh website, it will take longer time to get those data so it’s slower.
However, I just deployed some improvements for that, so you now should experience much much faster admin panel even with using “Variable” features.
Now create new page (or use existing one) and right click on that page > set source > and then choose that GET request you made
And for the last step for this to work, you need to configure proper route for page, in this case, we are using dynamic property id, so you need to configure route to be for example /something/:id
When source is configured, all the data for that single page are accessible using variable modal system under page > data keys.
I was able to set up the index page using the data from the GetAll API request, and then I set up the singular page using the data from the GetOne API request. I ran into an issue when I tried to link the two. The method of clicking on “Page” > “name of the singular page” didn’t work, BUT I was able to direct it to a link instead. I entered the URL for the singular page, and adding variable /${value->get(‘id’)} worked to direct it to the right spot.
One final question on this: is there any way to control the sorting of the elements in the GetAll request? Not a big deal if there isn’t, but I just thought I would ask.
Thank you so much for all of your help! You have saved me a lot of time and frustration.
You can still link to page in Settings tab, and then go to Advanced tab and you will see the that same ID property waiting for you to fill up with value (also you will have variable modal) so it’s easier for you.
Only way to sort in this case is with request it-self, so update the URL endpoint or add query parameters that Coda allows for filtering.
You can also do following for example
Add one more dynamic property sort for example, and se default value let’s say desc (this needs to match Coda API sorting docs)
Update route to be /something/:id/:sort
Now you can have multiple sorting using different urls for example /something/id/desc or /something/id/asc
So that’s how dynamic properties work.
You can also pass additional variables in route, let’s say if items has “name” you can do something like /something/:id/:name and then configure both id and name form Advanced tab, setting the name variable with function ->slug(), if you haven’t seen, in modal where you choose variables, you can add functions as well, and slug function converts string to slug, eg “This is name” to “this-is-name” so you get pretty page urls.