Question

Once more: You did not define `output`

  • 26 October 2023
  • 1 reply
  • 40 views

I have been through all of the docs and help topcis but I just do not get how zapier expects code in a java script zap to provide data.

Why is the output undefined? I tried to set output or use the callback (which i prefer). Nothing works :(

 

(function() {
const load = async () => {
const auth = "foo";
const url = `bar`;
const headers = {
"Authorization": `Basic ${auth}`,
"Content-Type": "application/json",
"X-Crisp-Tier": "plugin",
};
const options = {
method: "GET",
headers
};

const response = await fetch(url, options);
return await response.json();

}
load().then((response) => {
callback(null, response)
output = response
})
})()

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

FYI: returning the promise works, but I can’t use this approach because I am using typescript to create these scripts and `return` is not allowed outside function context

 

return (function() { // return works, but errors during compilation
const load = async () => {
const auth = "foo";
const url = `bar`;
const headers = {
"Authorization": `Basic ${auth}`,
"Content-Type": "application/json",
"X-Crisp-Tier": "plugin",
};
const options = {
method: "GET",
headers
};

const response = await fetch(url, options);
return await response.json();

}
return load(); // no output or callback used
})()