Get Document Library ID and metadata using SharePoint API

Instantly Get Document Library ID using SharePoint API

No comments

Loading

In this blog, we will learn about how to get Document Library ID and Document Library metadata using SharePoint API very quickly. The API is very simple to use. Before getting into the demo, let us understand what is document library in SharePoint Online.

What is Document Library in SharePoint Online?

A Document Library in SharePoint Online is a specialized type of list designed to store, organize, share, and manage documents. It provides a central location for users to collaborate on documents, track versions, and set permissions. Document Libraries are one of the most fundamental and widely used features in SharePoint for document management.

Key Features of Document Libraries

  1. Document Storage and Management
    • Store various types of files, including Word documents, Excel spreadsheets, PowerPoint presentations, PDFs, and more.
    • Organize files into folders and subfolders.
  2. Version Control
    • Track changes to documents with version history. Users can view, restore, or delete previous versions of a document.
  3. Metadata and Columns
    • Add custom columns to documents to capture metadata (e.g., author, document type, department).
    • Use metadata for sorting, filtering, and grouping documents.
  4. Co-Authoring and Collaboration
    • Multiple users can collaborate and edit documents simultaneously using Office Online.
    • Integration with Microsoft Teams for enhanced collaboration.
  5. Check-In/Check-Out
    • Users can check out documents to prevent others from making changes while they are being edited.
    • Check-in documents to make them available for others to edit.
  6. Permissions and Security
    • Set granular permissions at the library, folder, or document level.
    • Control who can view, edit, or delete documents.
  7. Workflows and Automation
    • Integrate with Power Automate to automate processes, such as approval workflows.
    • Use built-in SharePoint workflows for tasks like document approval and content approval.
  8. Integration with Office Applications
    • Direct integration with Microsoft Office applications for seamless editing and saving.
    • Open, edit, and save documents directly from Office apps like Word, Excel, and PowerPoint.
  9. Search and Navigation
    • Use SharePoint’s powerful search capabilities to find documents quickly.
    • Customize views and navigation to enhance document discovery.
  10. Document Sets
    • Group related documents together and manage them as a single entity using document sets.

How to Create and Use a Document Library

Step 1: Create a Document Library

  1. Navigate to Your SharePoint Site
    • Go to the SharePoint site where you want to create the document library.
  2. Create the Library
    • Click on the settings gear icon and select “Site contents.”
    • Click on the “New” button and select “Document library.”
    • Enter a name and description for the library.
    • Click “Create.”

Step 2: Configure the Document Library

  1. Add Columns
    • Go to the library settings by clicking on the settings gear icon and selecting “Library settings.”
    • Under “Columns,” click on “Create column” to add custom metadata fields.
  2. Set Up Versioning
    • In the library settings, click on “Versioning settings.”
    • Configure versioning options, such as enabling major and minor versions.
  3. Customize Views
    • Create custom views to display documents based on specific criteria (e.g., by department, by date).
  4. Set Permissions
    • In the library settings, click on “Permissions for this document library.”
    • Set permissions to control who can view, edit, and manage documents.

Step 3: Upload and Manage Documents

  1. Upload Documents
    • Click on the “Upload” button to add files from your computer.
    • Drag and drop files directly into the library.
  2. Check-In/Check-Out Documents
    • To check out a document, click on the ellipsis (…) next to the document and select “Check out.”
    • After editing, check the document back in to make it available for others.
  3. Collaborate and Co-Author
    • Open documents in Office Online to collaborate with others in real-time.
    • Use comments and track changes features in Office applications.

Example Use Case

Imagine a marketing team that needs to manage various marketing materials, including brochures, presentations, and reports. They can use a SharePoint Document Library to:

  1. Store and Organize Materials
    • Create folders for different types of materials (e.g., Brochures, Presentations, Reports).
    • Add metadata columns like Document Type, Campaign, and Date Created.
  2. Collaborate on Documents
    • Team members can co-author documents using Office Online.
    • Use version history to track changes and revert to previous versions if needed.
  3. Automate Approval Processes
    • Set up a Power Automate workflow to route documents for approval.
    • Notify team members when documents are approved or require changes.

By leveraging a Document Library in SharePoint Online, the marketing team can effectively manage, collaborate on, and streamline the approval process for their marketing materials.

Read AlsoMaster in List vs. document library SharePoint: when should we create a list or document library?

Quickly get document library ID using SharePoint API (Document Library in SharePoint)

API Format:

https://yoursposite/_api/v2.1/drives

Example:

globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/_api/v2.1/drives

The above API will return all custom document library metadata details from the given site.


{"@odata.context":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/_api/v2.1/$metadata#drives","value":[{"createdDateTime":"2020-07-26T14:33:16Z","description":"","driveType":"documentLibrary","id":"b!msQIKQFL1UW_lsAoicxd-O2X9TXUXihPn1c6zuY8860dUHq-Esw0QZRIgRXlHfVr","lastModifiedDateTime":"2020-10-25T13:47:24Z","name":"PNP Document Library","webUrl":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/PNP%20Document%20Library","createdBy":{"user":{"displayName":"Global SharePoint Diary","email":"Global-SharePoint2020@globalsharepoint2020.onmicrosoft.com","id":"f600af81-380d-4177-ac8b-d933bad711d5"}},"lastModifiedBy":{"user":{"displayName":"Global SharePoint Diary","email":"Global-SharePoint2020@globalsharepoint2020.onmicrosoft.com","id":"f600af81-380d-4177-ac8b-d933bad711d5"}},"owner":{"group":{"displayName":"Custom Search RND Owners","email":"CustomSearchRND@globalsharepoint2020.onmicrosoft.com"}},"quota":{"deleted":0,"fileCount":0,"remaining":27487790694400,"state":"normal","total":27487790694400,"used":0}},{"createdDateTime":"2020-07-26T14:20:47Z","description":"","driveType":"documentLibrary","id":"b!msQIKQFL1UW_lsAoicxd-O2X9TXUXihPn1c6zuY8863imYQkdWmpQaGIz_z39y0O","lastModifiedDateTime":"2020-07-26T14:20:47Z","name":"Document Library created by PowerShell","webUrl":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/Document%20Library%20created%20by%20PowerShell","createdBy":{"user":{"displayName":"Global SharePoint Diary","email":"Global-SharePoint2020@globalsharepoint2020.onmicrosoft.com","id":"f600af81-380d-4177-ac8b-d933bad711d5"}},"owner":{"group":{"displayName":"Custom Search RND Owners","email":"CustomSearchRND@globalsharepoint2020.onmicrosoft.com"}},"quota":{"deleted":0,"fileCount":0,"remaining":27487790694400,"state":"normal","total":27487790694400,"used":0}},{"createdDateTime":"2020-04-04T19:32:49Z","description":"","driveType":"documentLibrary","id":"b!msQIKQFL1UW_lsAoicxd-O2X9TXUXihPn1c6zuY8860bHJIBCeuvTas79btO0K3w","lastModifiedDateTime":"2020-07-10T04:36:55Z","name":"Documents","webUrl":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/Shared%20Documents","createdBy":{"user":{"displayName":"System Account"}},"lastModifiedBy":{"user":{"displayName":"Global SharePoint Diary","email":"Global-SharePoint2020@globalsharepoint2020.onmicrosoft.com","id":"f600af81-380d-4177-ac8b-d933bad711d5"}},"owner":{"group":{"displayName":"Custom Search RND Owners","email":"CustomSearchRND@globalsharepoint2020.onmicrosoft.com"}},"quota":{"deleted":0,"fileCount":1,"remaining":27487790694400,"state":"normal","total":27487790694400,"used":0}}]}

Get all custom document library metadata details using SharePoint API
Get all custom document library metadata details using SharePoint API

If we use the below API (just removing the ‘s’ from ‘drives’), we will get only the default out-of-the-box document library (“Documents”) metadata details.

https://yoursposite/_api/v2.1/drive

Example:

globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/_api/v2.1/drive

{"@odata.context":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/_api/v2.1/$metadata#drives/$entity","createdDateTime":"2020-04-04T19:32:49Z","description":"","driveType":"documentLibrary","id":"b!msQIKQFL1UW_lsAoicxd-O2X9TXUXihPn1c6zuY8860bHJIBCeuvTas79btO0K3w","lastModifiedDateTime":"2020-07-10T04:36:55Z","name":"Documents","webUrl":"globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/Shared%20Documents","createdBy":{"user":{"displayName":"System Account"}},"lastModifiedBy":{"user":{"displayName":"Global SharePoint Diary","email":"Global-SharePoint2020@globalsharepoint2020.onmicrosoft.com","id":"f600af81-380d-4177-ac8b-d933bad711d5"}},"owner":{"group":{"displayName":"Custom Search RND Owners","email":"CustomSearchRND@globalsharepoint2020.onmicrosoft.com"}},"quota":{"deleted":0,"fileCount":1,"remaining":27487785303593,"state":"normal","total":27487790694400,"used":5390807}}

Get Document library metadata details using SharePoint API

Get Document library metadata details using SharePoint API

Get Document library GUID ID from the document library settings page in SharePoint (Document library id SharePoint)

Another way, without the API we can get the document library GUID ID, from the document library settings page in SharePoint. Once we open the document library settings page, we can see the below URL where after “?List=” is the GUID ID of the document library but that comes in decoded format, we need to encode it.

globalsharepoint2020.sharepoint.com/sites/CustomSearchRND/_layouts/15/listedit.aspx?List=%7Bbe7a501d-cc12-4134-9448-8115e51df56b%7D

Get Document Library GUID ID from document library settings page in SharePoint
Get Document Library GUID ID from the document library settings page in SharePoint

Now, using the URL Decode Online tool, we can decode the above-highlighted text which is nothing but the GUID ID of the document library.

Decode SharePoint URL using the online decoder-encoder tool
Decode SharePoint URL using the online decoder-encoder tool

Note:

  • After decoding, whatever we can see inside the curly bracket is the GUID ID of the document library.

Summary: Get Document Library ID SharePoint

Thus, in this blog, we have learned the below with respect to SharePoint document library API:

  • How to get document library GUID ID using the SharePoint Online API?
  • How to get document library metadata details using the SharePoint Online API?

Reference: Document library in SharePoint

For more more on Microsoft Graph REST API refer to the below Microsoft Article:

Read Also: SharePoint Online Tutorials

You may also like the below SharePoint Online Tutorials:

About Post Author

Do you have a better solution or question on this topic? Please leave a comment