Module microsoft.sharepoint.sites

ballerinax/microsoft.sharepoint.sites Ballerina library

1.0.2

Overview

Microsoft SharePoint is a cloud-based collaboration and content management platform that enables organizations to create, share, and manage sites, documents, and resources securely across teams and enterprises.

The ballerinax/microsoft.sharepoint.sites package offers APIs to connect and interact with the Microsoft SharePoint Sites API endpoints, specifically based on Microsoft Graph REST API v1.0.

Setup guide

To use the Microsoft SharePoint Sites connector, you must have access to the Microsoft SharePoint API through a Microsoft Azure developer account and obtain client credentials by registering an application in Azure Active Directory. If you do not have a Microsoft account, you can sign up for one here.

Step 1: Create a Microsoft Account and Set Up SharePoint Access

  1. Navigate to the Microsoft 365 website and sign up for an account or log in if you already have one.

  2. Ensure you have a Microsoft 365 Business Basic, Business Standard, Business Premium, or an Enterprise (E1, E3, or E5) plan, as SharePoint Online and its API capabilities are restricted to users on these plans.

Step 2: Register an Application and Generate Credentials

  1. Log in to the Microsoft Azure Portal using your Microsoft 365 account credentials.

  2. In the left-hand navigation menu, select Microsoft Entra ID in the top search bar.

  3. In the left panel, navigate to App registrations and click New registration.

    New application registration

  4. Enter a name for your application, select the appropriate Supported account types (e.g., "Single tenant only"), and click Register.

    Application registration details

  5. Once the application is registered, note down the Application (client) ID and Directory (tenant) ID from the Overview page.

    Client ID and Tenant ID

  6. Navigate to Certificates & secrets in the left panel, click New client secret, provide a description and expiry period, then click Add. Copy the generated client secret value immediately.

    Create client secret

  7. Navigate to API permissions in the left panel and click Add a permission.

    Add API permission

  8. Select Microsoft Graph from the available API options.

    Microsoft Graph API permission

  9. Select Application permissions, then search for and add the following permissions depending on your use case, then click Add permissions.

    PermissionOperations covered
    Sites.Read.AllRead sites, lists, columns, content types, drives, analytics
    Sites.ReadWrite.AllCreate and update lists, list items, drives, and content
    Sites.Manage.AllUpdate site properties, create/delete columns and content types
    Sites.FullControl.AllManage site permissions

    Tip: Grant only the permissions your application actually requires. For read-only use cases, Sites.Read.All is sufficient. For full connector coverage, add all four.

    API site permissions

  10. Click Grant admin consent to approve the permissions for your organization.

    Grant admin consent

  11. Construct the tokenUrl using the Directory (tenant) ID obtained in step 5:

Copy
https://login.microsoftonline.com/<TENANT_ID>/oauth2/v2.0/token

Quickstart

To use the microsoft.sharepoint.sites connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Copy
import ballerinax/microsoft.sharepoint.sites;

Step 2: Instantiate a new connector

  1. Create a Config.toml file and configure the obtained credentials:
Copy
clientId = "<Your_Client_Id>"
clientSecret = "<Your_Client_Secret>"
tenantId = "<Your_Tenant_Id>"
  1. Create a sites:ConnectionConfig and initialize the client:
Copy
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string tenantId = ?;

final sites:Client msClient = check new ({
    auth: {
        clientId,
        clientSecret,
        tokenUrl: "https://login.microsoftonline.com/" + tenantId + "/oauth2/v2.0/token",
        scopes: ["https://graph.microsoft.com/.default"]
    }
});

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

Create a new list in a site

Copy
public function main() returns error? {
    sites:List newList = {
        displayName: "Project Documents",
        list: {
            template: "documentLibrary",
            contentTypesEnabled: true
        }
    };

    sites:List response = check msClient->createLists("contoso.sharepoint.com,abc123,def456", newList);
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

The microsoft.sharepoint.sites connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Site analytics dashboard - Demonstrates how to retrieve and visualize SharePoint site analytics data using the connector.
  2. Site permission audit cleanup - Illustrates auditing and cleaning up site permissions to maintain proper access control.
  3. Content governance audit workflow - Demonstrates how to automate content governance auditing workflows across SharePoint sites.
  4. Sharepoint drive inventory - Illustrates how to enumerate and inventory drives and their contents across SharePoint sites.

Import

import ballerinax/microsoft.sharepoint.sites;Copy

Other versions

Metadata

Released date: about 1 month ago

Version: 1.0.2

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 12

Current verison: 8


Weekly downloads


Source repository


Keywords

Area/Storage & File Management

Vendor/Microsoft

Type/Connector

Name/Microsoft SharePoint Sites


Contributors