Hello! I am attempting to make a Pack to fetch some data, and I have already added the addNetworkDomain pointing to the website
But I still get that error, something about “at processTicksAndRejections (node:internal/process/task_queues:96:5)”
Was trying to get data from this: Flipside Crypto
And the API provided is this: https://node-api.flipsidecrypto.com/api/v2/queries/91863551-69bb-47d5-8f3a-3a59113d9b91/data/latest
Hi @Shannelle_C - What domain did you use in your addNetworkDomain
call? Did you build a new version after adding it?
Hello! I didn’t build a new version, and I tried “flipsidecrypto.com” and “node-api.flipsidecrypto.com”
This error is very simple to overcome - you are declaring one domain, and using another. The domain in the call to the API must match the declared domain.
Hmmm, odd. I created this sample Pack that works fine:
import * as coda from "@codahq/packs-sdk";
export const pack = coda.newPack();
pack.addNetworkDomain("flipsidecrypto.com");
pack.addFormula({
name: "GetData",
description: "",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
name: "queryId",
description: "The ID of the Velocity query",
}),
],
resultType: coda.ValueType.String,
execute: async function ([queryId], context) {
if (!queryId) {
throw new coda.UserVisibleError("Invalid query ID: " + queryId);
}
let response = await context.fetcher.fetch({
method: "GET",
url: `https://node-api.flipsidecrypto.com/api/v2/queries/${queryId}/data/latest`,
});
let data = response.body;
return data;
},
});
Using the query ID you original posted fails, but due to the response being too large, not the network domain.
ah! that’s really helpful to know. Let me see what I can do on that end, but all in all, thank you so much for all the help!
Alright, I attempted to make it into something I could turn into a schema. I know my initial setup should be correct, but I think I get errors trying to return things?
Overview: Formula FlipsideData failed: Error at line 43: Cannot read property ‘VOTER’ of undefined
I don’t know if it’s because the things are in all caps? Managed to get a schema working before, and I did note that things needed to be in all caps over in Google Sheets and ImportJSON
execute: async function ([queryId], context) {
let url = `https://node-api.flipsidecrypto.com/api/v2/queries/${queryId}/data/latest`;
let response = await context.fetcher.fetch({
method: "GET",
url: url,
});
let results = response.body[queryId];
return {
voter: results.VOTER,
};
Alright, back from delirious attempts at things, and want to leave a comment if anyone else stumbles
- First problem is that API has a buncha values, but I’m doing it as formula, which usually delivers a tailored results
-
let results = response.body[queryId];
was an old piece of code that I copy/pasted. Rusty at this point, and that piece is wrong anyway. Doing let results = response.body[1];
gets the first item
- I was still getting errors, and I limited the initial query to 5, and voila, that loaded. All in all, I think this is better as a sync table
Happy to have gotten somewhere! Thanks for all the help everybody
Glad you are making progress!