Hey @robdodson,
Your mutation text seems correct (you can try it in our try it yourself GraphiQL explorer to make sure).
I believe that the issue is the JSON.stringify you have added over the body. This transforms the input into a JSON string while it expects a pure JSON.
Try it like this:
return fetch('https://api.monday.com/v2/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.MONDAY_TOKEN,
},
body: { "query": mutation },
})
.then(response => response.json());
Thanks for taking a look Ayelet!
Unfortunately I’m still hitting an issue. I’ve updated the code to match your description but now the response from the monday API is just ""
. When it tries to run response.json()
it throws an invalid json response body error. Also, the mutation doesn’t show up in the board.
I tested that the query works in GraphiQL, so it seems like there’s still something wrong with the way I’m calling create_items()
. Are you able to get this query to work on your end if you try with one of your own boards?
Hi @robdodson, Here’s an example of how to pass values to columns using the fetch api, hope this makes it more clear
const body = {
query: `
mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
create_item (
board_id: $boardId,
group_id: $groupId,
item_name: $itemName,
column_values: $columnValues
) {
id
}
}
`,
variables: {
boardId: MY_BOARD_ID,
groupId: "topics",
itemName: "New item name",
columnValues: JSON.stringify({ check: { checked: "true" } })
}
}
return fetch('http://api.monday.com/v2/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.MONDAY_TOKEN,
},
body: JSON.stringify(body),
})
.then(response => response.json());
Thank you Daniel, this seems to work!
For anyone checking this thread, there is one small thing I need to change. The url needs to be https:// NOT http://