Skip to main content

Hello,


I’m having a problem trying to pass JSON value to columnValues field when creating an item using monday.api() method.


Attempt #1:


monday.api(`
mutation {
create_item (
board_id: 0000000,
group_id: "topics",
item_name: "Hello",
columnValues: "${JSON.stringify({people3: {personsAndTeams: :{id: 1111111, kind: 'person'}]}})}"
) {
id
}
}
`);

Here is the error response I got:


{
"errors": :
{
"message": "Parse error on \\":{\\" (STRING) at t7, 36]",
"locations": :
{
"line": 7,
"column": 36
}
]
}
],
"account_id": 2222222
}

Since the attempt #1 doesn’t work for me, I’ve tried the solution that I found in this community, but it still doesn’t work for me.

Attempt #2:


    const body = {
query: `
mutation($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
create_item (
board_id: $boardId,
group_id: $groupId,
item_name: $itemName,
columnValues: $columnValues
) {
id
}
}
`,
variables: {
boardId: 00000000,
groupId: 'topics',
itemName: data.item,
columnValues: JSON.stringify({people3: {personsAndTeams: d{id: 111111111, kind: 'person'}]}})
}
}
monday.api(JSON.stringify(body));

Here is the error response that I got:


{
"errors": r
{
"message": "Parse error on \\"query\\" (STRING) at I1, 2]",
"locations": t
{
"line": 1,
"column": 2
}
]
}
],
"account_id": 2222222
}

Any help is appreciated.

Thank you.

Hello @pen123 ,

Welcome to the community 🙂


For your first attempt, your columnValues is a string within a string.

Also, it is column_values not columnValues

So instead of



Try this:


column_values: ${JSON.stringify({people3: {personsAndTeams: [{id: 1111111, kind: 'person'}]}})}

@kolaai I have tried it but it still doesn’t work. This is the error I’ve got:


{
"errors": s
{
"message": "Parse error on \\"people3\\" (STRING) at 7, 28]",
"locations": s
{
"line": 7,
"column": 28
}
]
}
],
"account_id": 1111111
}

Any idea why?


I have updated my answer


@kolaai I really appreciate your fast response. I’ve followed your suggestion but it’s so stubborn.

So with:


column_values: ${JSON.stringify({people3: {personsAndTeams: m{id: 1111111, kind: 'person'}]}})}

I got this error:


{
"errors": s
{
"message": "Parse error on \\"people3\\" (STRING) at 7, 33]",
"locations": s
{
"line": 7,
"column": 33
}
]
}
],
"account_id": 111111
}

I attempted with double quotes:


column_values: "${JSON.stringify({people3: {personsAndTeams: m{id: 1111111, kind: 'person'}]}})}"

I got a different error:


{
"errors": s
{
"message": "Parse error on \\":{\\" (STRING) at 7, 41]",
"locations": s
{
"line": 7,
"column": 41
}
]
}
],
"account_id": 111111
}

Solution: anyway, I’ve found the solution by using second parameter “options” and this is the right way to do it:


monday.api(`
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: 0000000,
groupId: 'topics',
itemName: 'new item',
columnValues: JSON.stringify({people3: {personsAndTeams: A{id: 1111111, kind: 'person'}]}})
}
});

Reply