0

在测试我的 Run Javascript 操作时,我收到以下错误

字符串:您没有定义“输出”!试试 `output = {id: 1, hello: await Promise.resolve("world")};`

当我的函数包含返回并且我的代码调用该函数时,我不明白为什么会发生这种情况。

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()
4

1 回答 1

0

尽管您的updateAccount()函数正确地等待请求本身完成,但没有什么可以告诉Code by Zapier函数等待updateAccount()完成。

您也不必在这里编写函数——“运行 Javascript”操作Code by Zapier已经将您的代码包装在一个async函数中。尝试以下操作:

const data = [
  {
    accountId: inputData.accountId,
    values: {
      "Became Customer": inputData.becameCustomer,
      "Total MRR": inputData.totalMRR,
      "Company Owner": inputData.companyOwner,
    },
  },
];

const response = 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>",
    },
  }
);

if (response.status !== 200) {
  throw new Error(`Unexpected status code ${response.status}`);
} else {
  return response;
}

于 2021-01-04T23:57:46.947 回答