我正在 Zapier 中构建自定义集成以与 Monday.com 集成。
应该发生的是用户将插入项目名称作为输入。该代码将查找所有项目并创建项目名称及其 ID 的字典(技术上讲是一个对象)。该字典应该使脚本能够查找项目名称的相应 project_id。
然后会有一些代码将项目插入该项目。
它目前的工作原理是它能够创建字典,但它似乎无法在字典中查找项目 ID,并吐出一个空结果。
我的代码:
//Create variable based on input from user
var project_name = bundle.inputData.project_id;
var dict = {};
//Look up all projects (id and name) in Monday.com
const options_ids = {
url: "https://api.monday.com/v2",
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${bundle.authData.access_token}`,
},
params: {},
body: {
query: "{ boards (ids:811745658){id name items { id name}}}",
},
};
// Create dictionary of all project names and ids in Monday.com
var p_ids = z.request(options_ids).then((response) => {
response.throwForStatus();
const results = z.JSON.parse(response.content);
var items = results.data.boards[0]["items"];
for (i = 0; i < items.length; i++) {
var key = items[i]["name"];
var value = items[i]["id"];
dict[key] = value;
}
return dict;
});
//Get the project ID of the project name that was entered as an input for use below
const project_id = p_ids[project_name];
const options = {
url: "https://api.monday.com/v2",
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${bundle.authData.access_token}`,
},
params: {},
body: {
// 'query': '{ boards (ids:811745658) {id name items {subitems {id name}} } }'
query: "{code to insert item to Monday project based on the project_id}",
},
};
return z.request(options).then((response) => {
response.throwForStatus();
items = response.json;
const results = response.json;
return results;
});