Problem with column_values and variables

Hi, struggling to use Graph API for basic stuff.

I can create new items in a board using long hand query mutation, but the same query wont work when using column_values.

This works fine

{
    "query": "mutation ($boardId: Int!, $itemName: String!){create_item(board_id: $boardId, item_name: $itemName, column_values: \"{\\\"text\\\":\\\"a text value\\\"}\"){id}}",
    "variables": {
        "boardId": 12345,
        "itemName": "new item"
    }
}

But when i try convert column_values to a variable, it doesn’t work, 500 Internal Server Error.

{
    "query": "mutation ($boardId: Int!, $itemName: String!, $columnValues: JSON!){create_item(board_id: $boardId, item_name: $itemName, column_values: $columnValues){id}}",
    "variables": {
        "boardId": 1234,
        "itemName": "new item",
        "columnValues": {
            "text": "some text"
        }
    }
}

you need to take the object that is the columnValues value and serialize it before adding it to the variables object.

const columnValues = JSON.stringify({text:"some text"});
const boardId = "1234";
const itemName = "new item";

const query = "mutation ($boardId: ID!, $itemName: String!, $columnValues: JSON!){create_item(board_id: $boardId, item_name: $itemName, column_values: $columnValues){id}}"

const variables = {
  boardId,
  itemName,
  columnValues,
}

const data = JSON.stringify({query,variables});

all that said! you look like you’re not using API-Version 2023-10. In 2023-10, board_id is now an ID type not Int. This can be a number or a string, but string is probably what you’ll use since queries return IDs as strings.

API Version 2023-07 will be discontinued January 15th, 2024. So less than 2 months! Just don’t want you to experience a break when its removed.

Ok i feel like i’m almost there, but still getting 500. I also included the API-Version:2023-10 header.

{
    "query": "mutation ($boardId: ID!, $itemName: String!, $columnValues: JSON!){create_item(board_id: $boardId, item_name: $itemName, column_values: $columnValues){id}}",
    "variables": "{\\\"boardId\\\":12345,\\\"itemName\\\":\\\"my item name\\\",\\\"columnValues\\\":\\\"text\\\":\\\"my text value\\\"}"
}

That looks like you passed the whole variables through serialization first. You need to just pass the value of columnValues through JSON.stringify() then use the string from that in the variables.

1 Like

You rippa!

Here is the working request.

{
    "query": "mutation ($boardId: ID!, $itemName: String!, $columnValues: JSON!){\n  create_item(board_id: $boardId, item_name: $itemName, column_values: $columnValues)\n    {id}\n}\n",
    "variables": {
        "boardId": 12345,
        "itemName": "new item",
        "columnValues": " {\"text\": \"my text value\"}"
    }
}
2 Likes

Thank you for the help here @codyfrisch !!

1 Like