How to display firstname and lastname in item query

I created an Item as follows and it got created successfully


$query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:641098600, item_name:$myItemName, column_values:$columnVals) { id } }';
$vars = ['myItemName' => "My Personal Task",
  'columnVals' => json_encode([
    'status' => ['label' => 'Done'], 
    'date4' => ['date' => '1993-08-27'],
'firstname1' => ['firstname' => 'Tony'],
'lastname1' => ['lastname' => 'Paul'],
])];

Now I want to query the items that I created as the code below to get item name, firstname, lastname etc.


$query = ' query{ items { id name  firstname lastname  } }';

Here is the error it displays

{"errors":[{"message":"Field 'firstname' doesn't exist on type 'Item'","locations":[{"line":1,"column":26}],"fields":["query","items","firstname"]},{"message":"Field 'lastname' doesn't exist on type 'Item'","locations":[{"line":1,"column":36}],"fields":["query","items","lastname"]}],"account_id":66xxxx}

Hello there @fredo!

With just some small tweaks, we can get this query working.

Column names are not fields that can be used to query items. Instead, we can make queries with column values to achieve the same result.

The issue with this query specifically is that firstname and lastname are not fields that can be used in the items query. (See Item query fields: https://api.developer.monday.com/docs/items-queries#fields)

In order to get column data, you can pass the column_values field with the ids argument to specify the exact columns you’d like to return using the column ID. (See Column Values query fields: https://api.developer.monday.com/docs/column-values)

Be sure to also include the boards field in your query, as it will make your call more specific.

This query will work instead:

query {
  boards (ids: 1234567890) {
    items {
      id
      name
      column_values (ids: ["examplecolumnID", "examplecolumnID"]) {
        title
        value
      }
    }
  }
}

Cheers,

Alessandra

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.