PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How do I create a new board item in Monday.com w/ column values? Code is not working

 November 06, 2022     monday.com, reactjs     No comments   

Issue

I'm using the Monday.com API in a React bootstrapped app.

I can create a new board item successfully with an item name...

monday.api(
    `mutation {
        create_item (
          board_id: ${myBoardId}, 
          group_id: "new_group", 
          item_name: "new item creation",
        )
        {
          id
        }
      }`
 )

...but when I try to add additional column values I get a POST 500 error.

monday.api(
    `mutation {
        create_item (
          board_id: ${myBoardId}, 
          group_id: "new_group", 
          item_name: "new item creation",
          column_values: {
            person: 00000000,
          }
        )
        {
          id
        }
      }`
 )

I've tried passing a string in for the column values...

let columnValues = JSON.stringify({
          person: 00000000,
          text0: "Requestor name",
          text9: "Notes",
          dropdown: [0],
        })

    monday.api(
      `mutation {
        create_item (
          board_id:${myBoardId}, 
          group_id: "new_group", 
          item_name: "test item",
          column_values: ${columnValues}
      )
        {
          id
        }
      }`
    ).then(res => {
      if(res.data){
        console.log('new item info: ', res.data)
      };
    });

...but no item is created, I get no errors and nothing logs.


Solution

Here was the solution:

const variables = ({
    boardId : 00000000,
    groupId: "new_group",
    itemName : "New Item",
    columnValues: JSON.stringify({
        people78: { 
            personsAndTeams: [
            {
                id: 00000000, 
                kind: "person"
            }
            ] 
        },
        text0: "Yosemite Sam",
        dropdown: {
            labels: [
            "TAM"
            ]
        },
    })
});

const query = `mutation create_item ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) { 
    create_item (
        board_id: $boardId,
        group_id: $groupId,
        item_name: $itemName, 
        column_values: $columnValues
    ) 
    { 
        id
    } 
}`;

monday.api(query, {variables}).then((res) => {
    console.log('new item info: ', res);
});


Answered By - sbaden
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing