Search code examples
javascriptsharepointmicrosoft-graph-apisharepoint-list

How to format POST request for Microsoft Graph API to create a new choice column on Sharepoint List with multi-select enabled?


I have a simple script that adds new columns to a specific List on my company's Sharepoint site. I am having trouble figuring out how to create a new column/column definition as a Choice Field that has Allow Multiple Selections enabled. Below is the working default choice column creation code:

const apiUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/columns`;
console.log(JSON.stringify(columnPayload));
// Make the API request to create the column
const response = await fetch(apiUrl, {
    method: "POST",
    headers: {
        Authorization: `Bearer ${accessToken}`,
        "Content-Type": "application/json",
    },
    body: JSON.stringify(columnPayload),
});

The column payload looks like this:

{
  "name": "Color",
  "choice": {
    "choices": ["Red", "Green", "Blue", "Purple"],
    "displayAs": "dropDownMenu"
  }
}

The resulting column then appears on the Sharepoint list: (Edit Column Field Selected to see more details) Column Settings View

If we expand the "More Options" we see that, as expected, the Allow Multiple Selections toggle is off. More Options

I have looked within the Graph API documentation and have not come across anything that lets us configure the fields that would have this option enabled. I only see the following options: From here: https://learn.microsoft.com/en-us/graph/api/resources/choicecolumn?view=graph-rest-1.0 Graph API Choice Field Description

When asking AI, it spits out something like this:

{
    name: "Categories",
    choice: {
        choices: ["Option1", "Option2", "Option3", "Option4"],
        allowMultipleValues: true,
        displayAs: "dropDownMenu",
    },
}

However, there is no mention of "allowMultipleValues" in the documentation. I ultimately will be setting up the columns, then adding Items, and some of which will have multiple options for a given Choice field.

Any guidance would be appreciated.


Solution

  • I think the multiple selections is controlled by the value of displayAs property.

    • If the value is dropDownMenu then you can select only one choice
    • If the value is checkboxes then you can select multiple choices
    {
      "name": "Color",
      "choice": {
        "choices": ["Red", "Green", "Blue", "Purple"],
        "displayAs": "checkBoxes"
      }
    }