I have performed the following steps within my Google Cloud Shell:
- npm i @codahq/packs-sdk -g
- coda init
- Copied the pack.ts content from this page “On your local machine - Coda Pack SDK”
- Then I have added an API request to the pack.ts (the final code can be found below)
- coda execute pack.ts Hello “world”
- I see the following error message (pasted below)
If I copy the code into the browser pack studio, it works (screenshot attached).
So it seems that it has something to do with the SDK.
I would be grateful if someone could help, because local development seems to be faster.
Thank you in advance.
ERROR MESSAGE:
TypeError: Cannot read property ‘status’ of undefined
at Object.handleFetcherStatusError (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4709:21)
at (:12:15)
at async Object.handleErrorAsync (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4696:14)
at async Object.execute (…/…/home/johannes/ga-pack2/pack.ts:25:20)
at async Object.findAndExecutePackFunction (/usr/local/nvm/versions/node/v12.14.1/lib/node_modules/@codahq/packs-sdk/dist/bundles/thunk_bundle.js:4580:14)
{
message: “Cannot read property ‘status’ of undefined”,
name: ‘TypeError’
}
CODE:
import * as coda from “@codahq/packs-sdk”;
export const pack = coda.newPack();
pack.addNetworkDomain(“httpbin.org”);
pack.addFormula({
name: “Hello”,
description: “A Hello World example.”,
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: “name”,
description: “The name you would like to say hello to.”,
}),
],
resultType: coda.ValueType.String,
execute: async function ([name], context) {
let payload = {
foo: “bar”,
};
let response = await context.fetcher.fetch({
method: "POST",
url: "https://httpbin.org/post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
const responseBody = JSON.stringify(response.body);
return "Hello " + responseBody;
},
});