JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Gallery
Pack Building Roadmap - Maker Stories Webinar
Share
Explore
Gallery
Pack Building Roadmap - Maker Stories Webinar
Pack Building Roadmap - Maker Stories Webinar
Webinar Outline
Roadmap
Travel Brief App
App Highlights
Pack Makers' Checklist
Pack Builder Interface
Pack Types
Pack Details & Code
TBCountries Code
TravelBriefData Code
Pack Data & Formulas
API Data
My Pack Formulas
Daylight | Weather Formulas
Wikipedia Pack
Data Tables
Getting Started with Packs
Build your Pack
Improve your Pack
Hello Fetcher Sample Code
Questions | Feedback
All Comments
Notes
Pack Details & Code
TravelBriefData Code
//Starter code for all packs
import
*
as
coda
from
"@codahq/packs-sdk"
;
export
const
pack = coda.newPack();
//Identify API domain name
pack.addNetworkDomain(
"travelbriefing.org"
);
//Create Schema and define property names for results
const
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 Formula
pack.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",
*/
Gallery
Share
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.