Hey @yuhaocooper
I’d love to help with this!
FIrst off, it doesn’t seem like you are sending your request with GraphQL Variables, but rather simply inputting the values from your code into the query. Is my understanding correct?
If you are not sending the Item Name as part of your variables, you will also need to properly escape it. Let me know if the following example makes sense;
const fetch = require('node-fetch');
let query4 = 'mutation ($myItemName: String!, $columnValues: JSON!, $boardId: Int!) { create_item (board_id:$boardId, item_name:$myItemName, column_values: $columnValues) { id } }';
let vars = {
"myItemName" : "Hello, world!",
"columnValues": "{\\"numbers\\":88}",
"boardId": 1199874661
};
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'ReplaceWithYourAPIKey'
},
body: JSON.stringify({
'query': query4,
'variables' : JSON.stringify(vars)
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
This works well for me on my end. Notice the escaping in column values as well 🙂
You can also avoid escaping by using JSON.stringify
dirctly within your variables, and the nagain in making your request:
let vars = {
"myItemName" : "Hello, world!",
"columnValues": JSON.stringify({"numbers":88}),
"boardId": 1199874661
};
body: JSON.stringify({
'query': query4,
'variables' : JSON.stringify(vars)
What do you think? Let me know.
-Alex
Hi @AlexSavchuk ,
Thanks for the examples! I’ve just changed my code to use the GraphQL variables and it is working on my end while following your formatting.
A separate issue I’m facing right now with the formatting of the GraphQL variable is with using the JSON.stringify directly on an array variable. E.g:
var personids = s{“id”:16200593,“kind”:“person”}, {“id”:9055423,“kind”:“person”}]
“columnValues”: JSON.stringify({“numbers”:num,“person”:{“personsAndTeams”:personids},“timeline”:{“from”:“2021-04-25”,“to”:“2021-04-27”}})
How should I format personids
or the columnValues
variable to make this work?
Best regards,
Yuhao
Hey @yuhaocooper
That’s a great question!
When wanting to assign multiple users to a People column using the API, you will need to send an array of User IDs, as well as the user kind (team/person). Here’s an example of how this query looks in the GraphQL playground:
mutation {
change_column_value (board_id: 1244760373, item_id: 1244760382, column_id: "person", value: "{\\"personsAndTeams\\": \{\\"id\\":9603417,\\"kind\\":\\"person\\"}, {\\"id\\":14205740, \\"kind\\":\\"person\\"}]}") {
id
}
}
From wha it looks like, you might need to add a right curly bracket after the Numbers column value you are sending. I hope this helps!
-Alex
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.