I need to Programatically be able to change the content type of the folders in a SharePoint Online Site.
I have Java Program that needs to run and detect if a folder has the correct Content Type and if not Change it.
This is how i have been triying to do it.
SiteRequestBuilder site = graphClient.sites(siteId); ContentType tfct = null; for (ContentType contentType : site.lists(listId).contentTypes().buildRequest().get().getCurrentPage()) { if (contentType.name.equalsIgnoreCase("Tagged Folder")) { tfct = contentType; break; } }
Here i detect and search for the Content Type i want the folder to have.
Then i do a recursive crawl by all the items, and if i detect the item is a folder i then need to change the content type.
request = graphClient .drives(driveId) .items(itemId) .children() .buildRequest(); DriveItemCollectionPage driveItems = request.get(); for (DriveItem driveItem :driveItems.getCurrentPage()){ if (driveItem.folder != null) { ListItem listItem = graphClient.drives(driveId).items(driveItem.id).listItem().buildRequest().get(); if(!listItem.contentType.id.equalsIgnoreCase(tfct.id)){ listItem.contentType.id = tfct.id; graphClient.sites(siteId).lists(listId).items(listItem.id).buildRequest().patch(listItem); } } }
But now when i run this code i get
[2024-03-25 21:28:04.253] ERROR main com.mcm.sharepoint.SharePointTaggerUtil Error listing drive items: Error code: invalidRequest Error message: Invalid request
Any one can give me a hand on either what is wrong or how can i change the ContentType and post it