zapier - Zapier:在一个触发器中从两个 API 端点提取数据
问题描述
我正在开发一个触发器,我需要从两个 API 端点提取数据。第一个端点是数据库中检索电子邮件地址的联系人,然后要获取该联系人(电子邮件)的详细信息,我需要使用另一个端点。一个是 /Subscriber,另一个是 /Subsriber/ {email}/ Properties。
我想知道我是否可以使用一个变量来获取一个触发器中的所有数据,因为我现在已经在单独的触发器中设置了。
这是两者的代码
订户:
url: 'https://edapi.campaigner.com/v1/Subscribers?PageSize=1',
method: 'GET',
headers: {
'Accept': 'application/json',
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'ApiKey': bundle.authData.ApiKey
}
};
return z.request(options).then((response) => {
response.throwForStatus();
const result = z.JSON.parse(response.content);
result.id = result.Items;
return [result];
});
和订阅者属性
const options = {
url: `https://edapi.campaigner.com/v1/Subscribers/${bundle.inputData.email_address}/Properties`,
method: 'GET',
headers: {
'Accept': 'application/json',
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'email_address': bundle.inputData.email_address,
'ApiKey': bundle.authData.ApiKey
}
}
return z.request(options).then((response) => {
response.throwForStatus();
const result = z.JSON.parse(response.content);
result.id = result.CustomFields;
return [result];
});
任何帮助表示赞赏。
</p>
解决方案
是的,绝对有可能!除非您的订阅者数据实际上需要是一个单独的触发器(这不太可能,因为您可能只是触发了新联系人),否则它可以只是一个函数。尝试类似:
const subscriberPerform = async (z, bundle) => {
const emailResponse = await z.request({
url: "https://edapi.campaigner.com/v1/Subscribers?PageSize=1",
method: "GET",
headers: {
Accept: "application/json",
"X-API-KEY": bundle.authData.ApiKey, // does this need to be both places?
},
params: {
ApiKey: bundle.authData.ApiKey, // does this need to be both places?
},
});
// requires core version 10+
const email = emailResponse.data.email;
const emailDataResponse = await z.request({
url: `https://edapi.campaigner.com/v1/Subscribers/${email}/Properties`,
method: "GET",
headers: {
Accept: "application/json",
"X-API-KEY": bundle.authData.ApiKey,
},
params: {
email_address: bundle.inputData.email_address, // lots of duplicated data here
ApiKey: bundle.authData.ApiKey,
},
});
return [emailDataResponse.data.SOMETHING];
};
这是一般的想法。这些 JS 函数可能根本不需要是触发器,这取决于您如何使用它们。
最后一点 - 您不想在每次轮询新联系人时都执行此额外查找;那很浪费。如果你这样做,请检查脱水。
推荐阅读
- javascript - 将日期值转换为可在 TestCafe 中使用的字符串
- python-3.x - 将目录中的所有 excel 文件读入数据框并使用文件名添加列
- google-chrome - 图标在 chrome 上显示为一些特殊字符
- apache-kafka - 如何使用kafka supervisor将kafka的一个特定分区中的数据读入druid
- javascript - 如何使用多个子键遍历 JSON 对象中的所有键并删除其中一些?
- php - 如果laravel validate中的外键相同,如何使名称唯一
- php - 如何通过链接在另一个页面中调用 PHP 类函数
- javascript - Javascript - 传递 URL/超链接参数以填充登录页面的输入字段
- c# - 如何在模板匹配中找到 ROI 内对象的旋转?
- node.js - 无法将 Angular 连接到 Nodejs 数据库(使用 cPanel 部署)