Hello,
I’m trying to create a Pack which uses data from a regular coda table. The Pack function has inputs which it compares to the table content with various statistics then the function returns a result. Currently the Pack is used in the same doc as the table is in but in future, the pack would be also used in other docs but still use the table from the original doc. Claude sonnet gave it’s best attempts but they failed (see below). What is the best way/is there a way to easily reference an regular table in a coda pack?
First attempt:
execute: async ([sex, bodyWeight, liftType, weightLifted], context) => {
const data = await context.fetcher.fetchTable(“LiftCategoryData”, {Sex: sex, LiftType: liftType});
error: * On line 279 Property ‘fetchTable’ does not exist on type ‘Fetcher’.
Second attempt:
execute: async ([sex, bodyWeight, liftType, weightLifted, age], context) => {
const data = await context.sync.fetchDataFromTable(“LiftCategoryData”, {Sex: sex, LiftType: liftType});
`
Error: * On line 301 Property ‘fetchDataFromTable’ does not exist on type ‘Sync’.
Third attempt:
execute: async ([sex, bodyWeight, liftType, weightLifted, age], context) => {
const table = coda.getTable(“LiftCategoryData”);
const data = await table.selectRows({
filter: coda.andFilters([
coda.makeFilter(table.getColumn(“Sex”), coda.FilterOperator.Equal, sex),
coda.makeFilter(table.getColumn(“LiftType”), coda.FilterOperator.Equal, liftType)
])
});
Errors:
- On line 301 Property ‘getTable’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
- On line 303 Property ‘andFilters’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
- On line 304 Property ‘makeFilter’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
- On line 304 Property ‘FilterOperator’ does not exist on type ‘typeof import(“@codahq/packs-sdk”)’.
- …
Fourth attempt:
execute: async ([sex, bodyWeight, liftType, age], context) => {
const data = await context.fetcher.fetchData(‘LiftCategoryData’, {
Sex: sex,
LiftType: liftType
});
Error:
- On line 301 Property ‘fetchData’ does not exist on type ‘Fetcher’.
Fifth attempt:
execute: async ([sex, bodyWeight, liftType, weightLifted, age], context) => {
const data = await context.sync.fetchSyncTable(“LiftCategoryData”);
const filteredData = data.filter(row => row.Sex === sex && row.LiftType === liftType);
Error:
- On line 301 Property ‘fetchSyncTable’ does not exist on type ‘Sync’.
Sixth attempt:
execute: async ([sex, bodyWeight, liftType, weightLifted, age], context) => {
const response = await context.fetcher.fetch({
method: “GET”,
url: “https://coda.io/apis/v1/docs/{doc_id}/tables/{table_id}/rows”,
headers: {
“Authorization”: “Bearer {your_coda_api_token}”
}
});
I didn’t try this one out as I couldn’t figure out what URL to use for this table and it seems overly complicated. But if it’s the only way to do it, that would be good to know.
Thanks,
Patrick