Step-by-Step Guide to Adding a Custom Content Type in SharePoint Library

Prerequisites

  • Access to Power Automate
  • A SharePoint Online site
  • Necessary permissions to create sites and manage content types

1. Create a SharePoint Site

First, we need to create a SharePoint site where the custom content type will be added.

POST https://<your-tenant>.sharepoint.com/_api/SPSiteManager/create

{

  “request”: {

    “Title”: “Your Site Title”,

    “Url”: “https://<your-tenant>.sharepoint.com/sites/YourSiteName”,

    “Lcid”: 1033,

    “ShareByEmailEnabled”: false,

    “Classification”: “Low Business Impact”,

    “Description”: “Site for your specific purpose”,

    “WebTemplate”: “STS#3”,

    “SiteDesignId”: “6142d2a0-63a5-4ba0-aede-d9fefca2c767”,

    “Owner”: “your-email@your-domain.com”,

    “WebTemplateExtensionId”: “00000000-0000-0000-0000-000000000000”

  }

}

2. Enable Content Type Management

Enable content type management on the default document library.

POST https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/web/lists/getbyTitle(‘Documents’)

{

  “__metadata”: { “type”: “SP.List” },

  “ContentTypesEnabled”: true

}

3. Get Compatible Content Types from the Content Type Hub

Retrieve compatible content types from the Content Type Hub.

GET https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/v2.0/sites/YourSiteName/ContentTypes/getCompatibleHubContentTypes

4. Add Custom Content Type from Content Type Hub

Use the addCopyFromContentTypeHub method to add the custom content type to the document library.

POST https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/v2.0/sites/YourSiteName/ContentTypes/addCopyFromContentTypeHub

{

  “contentTypeId”: “Your-Custom-ContentType-ID”

}

5. Add the Custom Content Type to the Document Library

Add the custom content type to the document library.

POST https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/web/lists/getbytitle(‘Documents’)/ContentTypes/AddAvailableContentType

{

  “contentTypeId”: “Your-Custom-ContentType-ID”

}

6. Get Default Content Type ID

Retrieve the default content type ID to remove it.

GET https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/web/lists/getbytitle(‘Documents’)/ContentTypes?$filter=Name eq ‘Document’

7. Remove Default Content Type

Remove the default content type from the document library.

POST https://<your-tenant>.sharepoint.com/sites/YourSiteName/_api/web/lists/getbytitle(‘Documents’)/ContentTypes(‘<Default-ContentType-ID>’)/deleteObject()

8. Save the Site URL in the Client Database (Optional)

Optionally, save the new site URL in your client database for future reference.

About the Author:

Shaheer Ahmad

As a Microsoft Certified Professional and Microsoft Learn Student Ambassador, I currently serve as a Power Platform & Dynamics 365 Consultant and Pod Lead at Cloud Surge. My dedication lies in delivering practical and user-friendly solutions, and I have a strong enthusiasm for learning and sharing knowledge. Active in the community, I find joy in helping others solve problems and have started sharing my learnings on my blog.

In terms of qualifications, I am pursuing a Bachelor’s Degree in Business & Information Technology at Virtual University. After completing my Intermediate in Computer Sciences in 2021, I chose to focus on enhancing my skills and career. I ventured into Microsoft Power Platform immediately after my Intermediate, and I have successfully obtained several certifications, including PL-900, MB-910, AI-900, PL-100, PL-200, MB-210, PL-400 and PL-600.

In my role, I am responsible for understanding client requirements and providing practical and user-friendly solutions using Power Platform, Dynamics 365, and Microsoft 365. My primary skills revolve around Microsoft Power Platform, especially Canvas Apps, as well as Microsoft 365 and Dynamics 365. Additionally, I have expertise in Graphics Designing and Networking.

As a fan and enabler of Microsoft Technologies, my goals include continuous learning and career growth, with an adaptive approach to new technologies. Actively participating in the Power Users Community, I strive to contribute by solving queries and offering practical solutions through my blog. Beyond work, I find pleasure in reading novels, playing badminton, and engaging in E-Sports.

Reference:

Ahmad, S (2024). Step-by-Step Guide to Adding a Custom Content Type in SharePoint Library. Available at: Step-by-Step Guide to Adding a Custom Content Type in SharePoint Library (shaheer365.blogspot.com) [Accessed: 26th September 2024].

Share this on...

Rate this Post:

Share: