When testing my Run Javascript action, I receive the following error
string: You did not define `output`! Try `output = {id: 1, hello: await Promise.resolve("world")};`
I don't understand why this is happening when my function includes a return and my code calls that function.
const updateAccount = async function(z, bundle) {
const data = [{
"accountId": inputData.accountId,
"values": {
"Became Customer": inputData.becameCustomer,
"Total MRR": inputData.totalMRR,
"Company Owner": inputData.companyOwner
}
}];
const promise = await fetch("https://app.pendo.io/api/v1/metadata/account/custom/value", {
method: "POST",
body: JSON.stringify(data),
headers: {
"content-type": "application/json",
"x-pendo-integration-key": "<my integration key>"}
});
return promise.then((response) => {
if (response.status != 200) {
throw new Error(`Unexpected status code ${response.status}`);
} else {
return response;
}
});
}
updateAccount()
Though your
updateAccount()
function correctly waits for the request to finish in itself, there's nothing to tell theCode by Zapier
function to wait forupdateAccount()
to finish.You also don't have to write a function at all here - the "Run Javascript" action in
Code by Zapier
already wraps your code in in anasync
function. Try the following: