Parse error with create_item and column_values

I’ve been trying to get the create_item mutation to work for a little while now but the server response tells me there’s a JSON parse error. I’ve tried escaping my column values manually and with JSON.stringify() but I always get the same error. Any help is much appreciated! Here’s my query:

const mutation = `
  mutation {
    create_item(board_id: MY_BOARD_ID, item_name: "a new item", column_values: "{\"check\": {\"checked\": \"true\"}}") {
      id
    }
  }
`;

return fetch('https://api.monday.com/v2/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': process.env.MONDAY_TOKEN,
    },
    body: JSON.stringify({ query: mutation }),
  })
  .then(response => response.json());

And here’s the error I get back in the response:

errors: [
  {
    message: 'Parse error on ": {" (STRING) at [3, 84]',
    locations: [Array]
  }
]

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());