Seems like you could do this with a Pack, but the exact details of how may be somewhat custom to your use case.
As a demo, here’s a somewhat awkward formula that gets multiple ranges from a spreadsheet when you call it like this: batchGet(’[spreadsheetId]’, [‘A2:C’, 'E10:E19])
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.addNetworkDomain("content-sheets.googleapis.com");
pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
tokenUrl: "https://oauth2.googleapis.com/token",
scopes: ["https://www.googleapis.com/auth/spreadsheets.readonly"],
});
// The free-form schema-less data from sheets doesn't maps so well
// to the more structured tables of Coda, so in practice you'd probably
// want to use your application's data type instead of something awkward
// like the array of array of numbers data type below.
const ValueSchema = coda.makeSchema({
type: coda.ValueType.Array,
items: { type: coda.ValueType.Number },
});
const RangeValuesSchema = coda.makeObjectSchema({
properties: {
range: { type: coda.ValueType.String },
values: {
type: coda.ValueType.Array,
items: ValueSchema
}
},
idProperty: "range",
displayProperty: "range",
});
const MultiRangeValuesSchema = coda.makeSchema({
type: coda.ValueType.Array,
items: RangeValuesSchema,
});
pack.addFormula({
name: "batchGet",
description: "Gets multiple ranges of values from a sheet",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "spreadsheetId",
description: "Spreadsheet ID",
}),
coda.makeParameter({
type: coda.ParameterType.StringArray,
name: "ranges",
description: "List of ranges to fetch",
}),
],
resultType: coda.ValueType.Object,
schema: MultiRangeValuesSchema,
execute: async function ([spreadsheetId, ranges], context) {
const result = await context.fetcher.fetch({
url: `https://content-sheets.googleapis.com/v4/spreadsheets/${encodeURIComponent(spreadsheetId)}/values:batchGet?` + ranges.map(r => 'ranges=' + encodeURIComponent(r)).join('&'),
method: 'GET',
});
return result.body.valueRanges;
},
});
To actually be able to run this code you’d need to set up a Google API project at Google Cloud Platform, add an OAuth2 client with “https://coda.io/packsAuth/oauth2” as a redirect URI, enable the Sheets API for your Cloud console project, and copy the client ID & client secret into your Pack configuration in the “Settings” tab for the Pack
When you log into sheets with your OAuth2 client ID you’ll also have to force your way through a big warning that tells you the app isn’t verified with Google, but then once you’re logged in you won’t have to worry about it