Skip to main content

UNAUTHORIZED_FIELD_OR_TYPE on create_item mutation

  • November 12, 2024
  • 6 replies
  • 93 views

dvdsmpsn
Forum|alt.badge.img+1

I’ve been using the following to create an item on a board:

export const createItem = async (variables: any, shortLivedToken: string) => {
	const monday = mondaySdk();
	monday.setToken(shortLivedToken);
	const query = `
        mutation createItem (
            $board_id: ID!
            $group_id: String!
            $item_name: String!
            $column_values: JSON!
        ){
            create_item (
                board_id: $board_id, 
                group_id: $group_id, 
                item_name: $item_name, 
                column_values: $column_values
            ) {
                id
            }
        }
    `;
	const options = { variables };
	const response = await monday.api(query, options);
	return response;
};

When passing this data in:

	const variables = {
		board_id: 7833822272,
		group_id: "topics",
		item_name: "Project Pivot",
		column_values: JSON.stringify({
			status: "14", // aka `Approved`
			date4: "2024-07-29 11:00:00",
			long_text: "Pivot demo",
			numbers3: 40
		})
	};
	const item = await createItem(variables, shortLivedToken);
	
	console.log(`Created item? "${itemName}":`, item );
	console.log(`variables:`, variables );

It gives me the following errors from the console.log lines:

Created item? "Project Pivot": {
	"errors": [
		{
			"message": "Unauthorized field or type",
			"path": [
				"create_item"
			],
			"extensions": {
				"code": "UNAUTHORIZED_FIELD_OR_TYPE"
			}
		}
	],
	"account_id": 11749326
}

variables: {
	"board_id": 7833822272,
	"group_id": "topics",
	"item_name": "Project Pivot",
	"column_values": "{\\"status\\":\\"14\\",\\"date4\\":\\"2024-07-29 11:00:00\\",\\"long_text\\":\\"Pivot demo\\",\\"numbers3\\":40}"
}

I think that this suggests there’s something odd about one of the fields UNAUTHORIZED_FIELD_OR_TYPE.

But when I look at the columns, using:

{
  boards(ids: [7833822272]) {
    columns {
      id
      type
      settings_str
    }
  }
}

I get the following:

{
  "data": {
    "boards": [
      {
        "columns": [
          {
            "id": "name",
            "type": "name",
            "settings_str": "{}"
          },
          {
            "id": "person",
            "type": "people",
            "settings_str": "{}"
          },
          {
            "id": "status",
            "type": "status",
            "settings_str": "{\\"done_colors\\":[1],\\"hide_footer\\":true,\\"color_mapping\\":{\\"1\\":14,\\"14\\":1},\\"labels\\":{\\"0\\":\\"Under consideration\\",\\"2\\":\\"Rejected\\",\\"7\\":\\"New request\\",\\"14\\":\\"Approved\\"},\\"labels_positions_v2\\":{\\"0\\":1,\\"2\\":3,\\"5\\":4,\\"7\\":0,\\"14\\":2},\\"labels_colors\\":{\\"0\\":{\\"color\\":\\"#fdab3d\\",\\"border\\":\\"#e99729\\",\\"var_name\\":\\"orange\\"},\\"2\\":{\\"color\\":\\"#df2f4a\\",\\"border\\":\\"#ce3048\\",\\"var_name\\":\\"red-shadow\\"},\\"7\\":{\\"color\\":\\"#579bfc\\",\\"border\\":\\"#4387e8\\",\\"var_name\\":\\"bright-blue\\"},\\"14\\":{\\"color\\":\\"#00c875\\",\\"border\\":\\"#00b461\\",\\"var_name\\":\\"green-shadow\\"}}}"
          },
          {
            "id": "date4",
            "type": "date",
            "settings_str": "{}"
          },
          {
            "id": "long_text",
            "type": "long_text",
            "settings_str": "{}"
          },
          {
            "id": "long_text9",
            "type": "long_text",
            "settings_str": "{}"
          },
          {
            "id": "anticipated_outcomes",
            "type": "long_text",
            "settings_str": "{}"
          },
          {
            "id": "numbers3",
            "type": "numbers",
            "settings_str": "{\\"unit\\":{\\"symbol\\":\\"$\\",\\"custom_unit\\":\\"\\",\\"direction\\":\\"left\\"}}"
          },
          {
            "id": "button__1",
            "type": "button",
            "settings_str": "{}"
          }
        ]
      }
    ]
  },
  "account_id": ...
}

All column types and values look perfectly reasonable.

What could be the reason for the UNAUTHORIZED_FIELD_OR_TYPE error message?

6 replies

dvdsmpsn
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 13, 2024

What makes this weirder is when I get the mutation:

mutation createItem($board_id: ID!, $group_id: String!, $item_name: String!, $column_values: JSON!) {
  create_item(
    board_id: $board_id
    group_id: $group_id
    item_name: $item_name
    column_values: $column_values
  ) {
    id
  }
}

and the variables:

{
  "board_id": 7843759455,
  "group_id": "topics",
  "item_name": "Project Pivot",
  "column_values": "{\\"status\\":\\"14\\",\\"date4\\":\\"2024-07-29 11:00:00\\",\\"long_text9\\":\\"This Pivot demo\\",\\"numbers3\\":40}"
}

and push it through the api playground ui, the item is created fine.

It also works with the exact same data on my dev and staging accounts, just not on my production account when using the code in the original post.


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • November 17, 2024

Hello there @dvdsmpsn,

Would you be able to please fill this form adding as much information as possible to it so that our team can take a look into it?

Cheers,
Matias


dvdsmpsn
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 17, 2024

Done. (#3719361)


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • November 18, 2024

Thank you @dvdsmpsn !


dvdsmpsn
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • November 18, 2024

Hi @Matias.Monday

Just to update you.

I added the missing board:write OAuth scope and now everything works just fine.

Thanks so much for your help on this one.

– David


Matias.Monday
Forum|alt.badge.img
  • monday.com Team Member
  • November 19, 2024

Happy to help @dvdsmpsn !!!