Pack Building Roadmap - Maker Stories Webinar
Share
Explore
Pack Details & Code

icon picker
TravelBriefData Code

//Starter code for all packsimport * as coda from "@codahq/packs-sdk";export const pack = coda.newPack();
//Identify API domain namepack.addNetworkDomain("travelbriefing.org");

//Create Schema and define property names for resultsconst TBSchema = coda.makeObjectSchema({ properties: { name: {type: coda.ValueType.String}, continent: {type: coda.ValueType.String}, timezone: {type: coda.ValueType.String}, electricityVolts: {type: coda.ValueType.String}, electricityPlugs: {type: coda.ValueType.String}, languages: {type: coda.ValueType.String}, currency: {type: coda.ValueType.String}, telephoneCode: {type: coda.ValueType.String}, emergency: {type: coda.ValueType.String}, }, displayProperty: "name",});

//Add a Formulapack.addFormula({ name: "TravelBriefData", description: "Returns the travel brief details for a given country.", parameters: [coda.makeParameter({ type: coda.ParameterType.String, name: "Country", description: "The country to fetch", }), ],

//Display object results as defined in the schema in the variable "data". resultType: coda.ValueType.Object,schema: TBSchema,
execute: async function ([Country], context) { let url = "https://travelbriefing.org/" + Country + "?format=json"; let response = await context.fetcher.fetch({ method: 'GET', url }); let data = { name: response.body.names.name, continent: response.body.names.continent, timezone: response.body.timezone.name, electricityVolts: response.body.electricity.voltage, electricityPlugs: response.body.electricity.plugs, languages: response.body.language, currency: response.body.currency, telephoneCode: response.body.telephone.calling_code, emergency: response.body.telephone.police, }; return data; } });
/* Postman Response to API GET Call
"names": {
"name": "Netherlands",
"full": "Kingdom of the Netherlands",
"iso2": "NL",
"iso3": "NLD",
"continent": "EU"
},
"maps": {
"lat": "52.2129919",
"long": "5.2793703",
"zoom": "7"
},
"timezone": {
"name": "Europe/Amsterdam"
},
"language": [
{
"language": "Dutch",
"official": "Yes"
}
],
"electricity": {
"voltage": "230",
"frequency": "50",
"plugs": [
"C",
"F"
]
},
"telephone": {
"calling_code": "31",
"police": "112",
"ambulance": "112",
"fire": "112"
},
"water": {
"short": "safe",
"full": ""
},
"vaccinations": [],
"currency": {
"name": "Euro",
"code": "EUR",
"symbol": "€",
"rate": "0.924695",
*/

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.