1

I tried to add a new content type to list using MS Graph Explorer:

Request:

POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/contenttypes

with body:

{
  "description": "MyCustomContentType's description",
  "group": "List Content Types",
  "hidden": false,
  "id": "0x010300B8123BA6FE3D6045BF4F6DF992B6ABE7",
  "name": "MyCustomContentType",
  "parentId": "0x0103",
  "readOnly": false,
  "sealed": false
}

Response:

{
    "error": {
        "code": "itemNotFound",
        "message": "The specified site content type was not found",
        "innerError": {
            "request-id": "1ac12fed-eaf3-4d03-a3c4-b44ddacada72",
            "date": "2020-05-16T17:12:11"
        }
    }
}

Also tried this with Graph API sdk in Java code:

IGraphServiceClient graphClient = GraphServiceClient.builder()
        .authenticationProvider(authenticationProvider)
        .buildClient();

ContentType contentType = new ContentType();
contentType.name = "MyCustomContentType";
contentType.description = "MyCustomContentType's description";
contentType.group = "List Content Types";
contentType.hidden = false;
contentType.parentId = "0x0103";
contentType.id = "0x010300B8123BA6FE3D6045BF4F6DF992B6ABE7";
contentType.readOnly = false;
contentType.sealed = false;

contentType = graphClient.sites(siteId)
        .lists(listId)
        .contentTypes()
        .buildRequest()
        .post(contentType);

the result is the same...

Also I tried to add content type to list using REST API but faced with another problem: content type is created but it ignores passed id and always inherited from Item content type. The same problem described here: How to create a SharePoint content type with 'Document' as the parent. It seems like a bug of REST API.

Is it possible to create a content type in SharePoint using MS Graph or REST API? Maybe there are other ways to create it using Java?

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.