我有这个问题,但我在这里找不到解决方案。所以我决定分享我发现的基础知识。
我假设您已经拥有令牌。
首先,您需要 httr 和 jsonlite 来处理查询和帖子以及 json 响应。
然后,从您感兴趣的版块中,例如上图中的版块,您需要 id。
然后我们需要每列(除了 item 列)的 id,我们使用以下查询
query <- '{
boards(ids: [7417519601]) {
name
columns {
title
id
type
}
groups {
title
id
}
}
}'
然后我们发送 POST(我假设响应成功)
response <- POST(
url = "https://api.monday.com/v2",
add_headers(Authorization = apiKey),
body = list(query = query),
encode = "json"
)
转换响应后,我们检查列类型及其 ID
data <- content(response, as = "text")
data_json <- fromJSON(data, flatten = TRUE)
data_json$data$boards$columns |> as.data.frame() |> View()
检查 API Playground 中的查询很有用。
我们还需要组id,可以通过查询找到
query <- '
{
boards (ids: 7417519601) {
groups {
id
title
}
}
}
'
在与之前相同的响应代码和 json 处理之后,我们检查组 id
data_json$data$boards$groups |> as.data.frame() |> View()
我们的板块名为“Principal”,但它的id是“topics”
现在我们将发布一个项目。有些类型最初很棘手,因此在 API Playground 中检查现有项目(如果有人需要,我可以稍后添加示例)也很有帮助。
为此,我们需要一个突变:
mutation <- sprintf('
mutation {
create_item (
board_id: 7417519601,
group_id: "topics",
item_name: "An item 1", #can be sent as parameter too
column_values: \"{
\\\"text__1\\\":\\\"%s\\\",
\\\"numbers__1\\\":\\\"%d\\\",
\\\"date4\\\":\\\"%s\\\",
\\\"email__1\\\": {\\\"text\\\": \\\"%s\\\" , \\\"email\\\": \\\"%s\\\" },
\\\"status\\\":{\\\"index\\\":%s}
}\")
{
id
name
}
}
', "Neo", 42, "2024-09-11", "[email protected]", "[email protected]", 0
)
及其帖子
response <- POST(
url = "https://api.monday.com/v2",
add_headers(Authorization = apiKey),
body = list(query = mutation),
encode = "json"
)
如果查询有拼写错误或其他问题,响应会成功,但不会到达群组。
也许这太基础了,但我想有人可以用它作为开始,即使我们周围有 chat-gpt。