Reputation: 151
I had this question and I couldn't find solutions here. So I decided to share the basics that I found.
Upvotes: 1
Views: 29
Reputation: 151
I'll asumme you already have your token.
First of all you need httr and jsonlite to handle queries and posts, and json responses.
Then, from the board you are interested, for example as the one in the image above, you need the id.
Then we need the id from each column (besides the item column), we use the following query
query <- '{
boards(ids: [7417519601]) {
name
columns {
title
id
type
}
groups {
title
id
}
}
}'
Then we send the POST (and I'll assume the response is successful)
response <- POST(
url = "https://api.monday.com/v2",
add_headers(Authorization = apiKey),
body = list(query = query),
encode = "json"
)
After converting the response, we check the column types and their id's
data <- content(response, as = "text")
data_json <- fromJSON(data, flatten = TRUE)
data_json$data$boards$columns |> as.data.frame() |> View()
Checking the queries in the API Playground is useful.
We also need the group id, which can be found with the query
query <- '
{
boards (ids: 7417519601) {
groups {
id
title
}
}
}
'
After the same response code and json handling as before, we check the group id
data_json$data$boards$groups |> as.data.frame() |> View()
Our group is called "Principal", but it's id is "topics"
Now we will post an item. Some types are initially tricky, so checking in the API Playground for existing items (I could add an example later if someone needs to) can be helpful too.
For this we need a mutation:
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
)
and its POST
response <- POST(
url = "https://api.monday.com/v2",
add_headers(Authorization = apiKey),
body = list(query = mutation),
encode = "json"
)
If the query has a typo or something, the response will be successful, but it won't reach the group.
Maybe this is too basic, but I wanna think there is someone out there that could use this as a start, even with chat-gpt around us.
Upvotes: 1