【问题标题】:Zapier You did not define output error when return and call includedZapier 包含返回和调用时,您没有定义输出错误
【发布时间】:2021-03-19 21:17:16
【问题描述】:

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

string: 你没有定义`输出`!尝试`output = {id:1,你好: 等待 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()

【问题讨论】:

    标签: javascript zapier pendo


    【解决方案1】:

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

    您也不必在此处编写函数 - Code by Zapier 中的“运行 Javascript”操作已经将您的代码包装在 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-08-06
      • 2020-11-06
      • 1970-01-01
      • 2019-07-28
      • 2017-06-13
      • 2018-11-27
      • 1970-01-01
      • 2018-12-26
      • 2019-09-06
      相关资源
      最近更新 更多