Formatting for creating people, link, and number items (google app script)

I’m really struggling with syntax and formatting in google app script. As a baseline, this works for creating an item on a board:

const BASE_URL = 'https://api.monday.com/v2';
const dealBoardId = '5533299122';  //Deals board in the test workspace

function createMondayDeal() {
  let query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:' + dealBoardId + ', item_name:$myItemName, column_values:$columnVals) { id } }';

  let vars = {
    "myItemName": "Hello, Best Deal!",
    "columnVals": JSON.stringify({
      "deal_stage" : {"label" : "New"},
      "status9" : {"label" : "1"},
    })
  };


  var response = UrlFetchApp.fetch("https://api.monday.com/v2", {
    method: 'post',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': API_KEY,
      'API-Version' : '2023-04'
    },
    payload: JSON.stringify({
      'query': query,
      'variables': JSON.stringify(vars)
    })
  })

However, expanding to include a link fails::

This fails with status code 200, invalid value:

  let vars = {
    "myItemName": "Hello, Best Deal!",
    "columnVals": JSON.stringify({
      "link": { "link": "https://www.google.com", "text" : "google"},
      "deal_stage" : {"label" : "New"},
      "status9" : {"label" : "1"},
    })
  };

and this fails silently (successfully creates item with without the link:

  let vars = {
    "myItemName": "Hello, Best Deal!",
    "columnVals": JSON.stringify({
      "link": { "link": "https://www.google.com"},
      "deal_stage" : {"label" : "New"},
      "status9" : {"label" : "1"},
    })
  };

Trying to include a people column also fails with status code 200, “Link to item column value structure invalid”:

"deal_contact" : {"people" : {"personsAndTeams" : [ {"id" : "5936051010", "kind" : "person"} ] } }

Review the example change_multiple_column_values for some syntax on link columns:

mutation {
  change_multiple_column_values(item_id:9876543210, board_id:1234567890, column_values: "{\"link\" : {\"url\" : \"http://monday.com\", \"text\":\"go to monday!\"}}") {
    id
  }
}

note its url not link for the key for the url in the change object. Secondly I have to assume your column ID is actually link?

In the second case, it seems the deal_contact is a connect boards column, not a people column. That means you’re picking contact items from another board, not users from your account. 5936051010 is an item ID not user ID. See below for the structure of a connect boards column.

mutation {
  change_multiple_column_values(item_id:9876543210, board_id:1234567890, column_values: "{\"connect_boards\" : {\"item_ids\" : [12345, 23456, 34567]}}") {
    id
  }
}

Lastly… API 2023-04 is very much gone, you might be able to get 2023-07 through february 15th if you extend your user token. 2024-01 is current, and 2024-04 is release candidate. Maybe you meant to be trying 2024-04?

Thank you Cody for the quick response. I updated my api to 2024-01. yes, “link” is the column ID as well. I changed the column type to “url” and that works. I was referencing Column types reference, which seems to say that “link” should be the column type? Where should I be looking in the future?

Thanks for pointing me in the right direction on connect boards. Trying this:

"deal_contact" : {"connect_boards" : {"item_ids" : ["5939178365"]}}

gives me “status_code”:200,“error_message”:“Link to item column value structure invalid”,“error_data”:{}}

doubling checking, seems like my item id is correct for an item on the connected board for that column. So not sure about that. Will keep debugging…

ok, not sure where to go from here. I believe that item id and column setup (board linking) and column id are correct. Is there a formatting issue with this query?

Additional issue/question:

  "deal_owner" : {"people" : {"personsAndTeams" : [ {"id" : "50584368", "kind" : "person"} ] } }

seems to fail silently. New deal item is created with all other column values, but deal_owner is left blank. I double checked people id by manually assigning person and then doing a query of the board with this result:

“id”:“deal_owner”,“type”:“people”,“value”:"{"changed_at":"2023-11-18T02:48:26.188Z","personsAndTeams":[{"id":50584368,"kind":"person"}]}

What am I missing?

“connect_boards” and “people” are the column IDs, you should use your own column IDs like as follows.

"deal_contact" : {"item_ids" : ["5939178365"]}
"deal_owner" : {"personsAndTeams" : [ {"id" : "50584368", "kind" : "person"} ] }

1 Like

awesome that worked, thank you!

1 Like

Thank you @anon29275264 !!

1 Like