Here’s my IMDB pack so far if you want to take it for a spin:
Right now it’s just movies and needs work on filtering the search results, but basically you set your column type to IMDBMovie, write a movie title in the cell, and it’ll return a rich object that you can pull columns off of for poster, runtime, etc.
Let me know if you want to collaborate on it and I’ll throw it up on github
// Initialize Packs SDK and create the pack
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
// IMDB doesn't have a publicly-available API, but RapidAPI provides one with free and paid tiers
// https://rapidapi.com/apidojo/api/imdb8/
pack.addNetworkDomain('rapidapi.com');
pack.setUserAuthentication({
type: coda.AuthenticationType.CustomHeaderToken,
headerName: "x-rapidapi-key",
instructionsUrl: "https://coda.io/@nickhe/imdb-pack"
});
// Movie schema
const movieSchema = coda.makeObjectSchema({
type: coda.ValueType.Object,
properties: {
Title: {type: coda.ValueType.String},
Year: {type: coda.ValueType.Number},
Runtime: {
type: coda.ValueType.String,
codaType: coda.ValueHintType.Duration,
// fromKey: "runningTimeInMinutes",
},
Poster: {
type: coda.ValueType.String,
codaType: coda.ValueHintType.ImageReference,
// fromKey: "image.url",
},
IMDBId: {type: coda.ValueType.String},
},
primary: "Title",
featured: ["Title", "Year", "Poster"],
id: "IMDBId",
// identity: {name: "IMDBMovie"}
});
pack.addColumnFormat({
name: "IMDB Movie",
instructions: "Shows movie details from IMDB",
formulaName: "IMDBMovie",
formulaNamespace: "Deprecated",
});
pack.addFormula({
name: "IMDBMovie",
description: "Search for a movie and get details about it from IMDB",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "query",
description: "Search IMDB (try movie name, or movie name and year)",
}),
],
resultType: coda.ValueType.Object,
schema: movieSchema,
execute: async function ([query], context) {
const url = "https://imdb8.p.rapidapi.com/title/find?q=" + encodeURIComponent(query);
const response = await context.fetcher.fetch({
method: 'GET',
headers: {
"x-rapidapi-host": "imdb8.p.rapidapi.com",
},
url: url
});
const movie = response.body.results[0];
return {
// grab the ID (tt0109830) out of the API's id response (/title/tt0109830/)
IMDBId: movie.id.replace("/title/","").replace("/",""),
Title: movie.title,
Year: movie.year,
Runtime: movie.runningTimeInMinutes + " minutes",
Poster: movie.image.url,
}
},
});