Creating subitem with column_values

Hi, I have some code to create a subitem in Monday.com (i’m using Zapier to dynamically pull variables from Xero).

The code works fine and creates the subitems however I’m unable to get it to set column values (setting “Hello” as dummy text for testing).

Code is below. Any help would be much appreciated.

The error is a 500 error:

ResponseError: {"status":500,"headers":{"content-type":"application/json; charset=utf-8"},"content":"{\"error_message\":\"Internal server error\",\"status_code\":500}"

Code:

var project_name = bundle.inputData.project_id;

var dict = {};

function get_id(id){
  return parseInt(id)
}

const options_ids = {
  url: 'https://api.monday.com/v2',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`
  },
  params: {

  },
  body: {
   'query':"{  boards (ids:BOARDID){id name items { id name}}}"
        }
}

return z.request(options_ids)
  .then((response) => {
  // response.throwForStatus();
    // var project_id = ""
    const results = JSON.parse(response.content);
    var items =  results.data.boards[0]['items'];
    for(i=0;i<items.length;i++){
    var key = items[i]['name']
    var value = results.data.boards[0]['items'][i]['id']
    dict[key] = value
    }
const mutation = "mutation {create_subitem (parent_item_id: "+dict[project_name]+", item_name: \"Expense: "+bundle.inputData.description+" - "+bundle.inputData.amount+" "+ bundle.inputData.currency+ "\",column_values:{text_value:Hello}) {id,board {id}}}"
const options = {
  url: 'https://api.monday.com/v2',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`
  },
  params: {
  },
  body: {
    'query':mutation
  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    items = response.json;
    const results = response.json;
    
    
    return results
  })

})

Hey @emvy03 - welcome to the community!

I think the issue here is tied to two issues: the column being identified in the 'column values' portion, and the formatting of the string being sent to fill in the column value.

When setting column values you’ll want to make sure you’re sending a JSON string, and that the column being specified matches the column ID you see in the interface.

In my particular case, the column ID was just ‘text’:

image

With this information, I was able to create a subitem with pre populated content by sending a JSON string to the API:

mutation { 
      create_subitem (
        parent_item_id: xxxxxx, 
        item_name: "My Subitem Test",
        column_values:"{\"text\": \"Testing API\"}"
        ) { id } 
}

Hope this helps - let me know if you have any other questions.

-Daniel