Microsoft Graph API get list of columns associated with a content type

1.3k Views Asked by At

Is it possible through the Microsoft Graph API to enumerate the columns associated with a content type? For example, you can enumerate the columns for a particular document library using the following endpoint

https://graph.microsoft.com/v1.0/drives/{drive id}/list?$expand=columns

The response will contain an array of available columns something like the following

"columns": [
  ...
  {
    "columnGroup": "Custom Columns",
    "description": "",
    "displayName": "Title",
    "enforceUniqueValues": false,
    "hidden": false,
    "id": "fa564e0f-0c70-4ab9-b863-0177e6ddd247",
    "indexed": false,
    "name": "Title",
    "readOnly": false,
    "required": false,
    "text": {
      "allowMultipleLines": false,
      "appendChangesToExistingText": false,
      "linesForEditing": 0,
      "maxLength": 255
    }
  },
  ...

This works fine for document libraries that have only a single content type, but I am working with libraries that may use multiple content types and I need to be able to list the columns that are associated with each content type.

The basic issue is that our app will upload documents to SharePoint and then try to update the metadata on those documents by setting the fields in the document's list item, i.e.,

PATCH https://graph.microsoft.com/v1.0/drives/{drive id}/items/{item id}/listitem
{
  "fields": {
    "Comments": "comments",
    "Title": "document title"
    ...
  }
}

However, the list of fields to be updated by our app is dynamic, and if a field is included in this call that does not exist in the libraries columns, the call will fail. For example, if the target content type does not have a Comments column, the call would return this error

{
  "error": {
    "code": "invalidRequest",
    "message": "Field 'Comments' is not recognized",
    "innerError": {
      "date": "2020-12-11T15:55:57",
      "request-id": "35fa6322-caa8-48b8-b2bd-59e3dd4e0c93",
      "client-request-id": "35fa6322-caa8-48b8-b2bd-59e3dd4e0c93"
    }
  }
}

So I need to determine which fields are available before trying to update their values so they can be excluded from the call.

1

There are 1 best solutions below

0
On

I think that you could make such call:

https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/contentTypes?$expand=columns