Nota
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tidħol jew tibdel id-direttorji.
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tibdel id-direttorji.
This guide walks you through setting up and testing the server logic sample that integrates Power Pages with Microsoft Graph and SharePoint online.
Step 1: Download the sample package
- Go to the GitHub repository https://github.com/microsoft/power-pages-samples.
- Select Code > Download ZIP.
- After downloading, extract the ZIP file to a local folder, for example:
C:\PowerPages\ServerLogic - Navigate to the extracted path:
samples/server-logic/sharepoint-integrationThis folder contains theevent-registration.zipsolution package, which includes the Power Pages site resources you will import in later steps.
Alternatively, use git clone if you prefer.
git clone https://github.com/microsoft/power-pages-samples.git
cd power-pages-samples/samples/server-logic/sharepoint-integration
Step 2: Prerequisites
Before you start, make sure you have:
- Access to Microsoft Entra ID (Azure AD) with permission to register apps.
- Access to a SharePoint Online site (for example, https://contoso.sharepoint.com/sites/EventSite).
Step 3: Create and configure the Entra ID application
You need an app registration to allow your server logic code to authenticate against Microsoft Graph.
Create the app registration
- Go to the Azure Portal, and select App registrations.
- Select + New registration.
- Provide a name (for example, PowerPages-Graph-Integration).
- Choose Accounts in this organizational directory only.
Note
You don't need to provide a redirect URI for this sample.
- Select Register.
Configure API permissions
- In the new app, go to API Permissions > Add a permission.
- Select Microsoft Graph > Application permissions.
- Add the following permissions:
- Sites.ReadWrite.All (for SharePoint file operations)
- Mail.Send (optional – only needed if you plan to enable the email section)
- Select Grant admin consent for your tenant.
Create a client secret
- Go to Certificates & secrets > Client secrets.
- Select + New client secret.
- Enter a description and choose an expiry period (for example, six months).
- Select Add, and copy the generated value immediately—this is your CLIENT_SECRET.
Collect required values
From your Azure app:
- Client ID > CLIENT_ID
- Tenant ID > TENANT_ID
- Client Secret > CLIENT_SECRET
Step 4: Identify your SharePoint site and folder
The script uploads generated event tickets to a SharePoint site.
- Identify your SharePoint hostname and site path:
For example: HOSTNAME =
contoso.sharepoint.comSITE_PATH =/sites/EventSite - Ensure a document library called Documents exists (default).
Step 5: Deploy the package
Create a new site by importing the recently downloaded site from GitHub. To learn how to import the site, see power-pages-solutions
During the site upgrade, update the values for environment variables. Update the following values that you captured in previous steps:
- Client ID
- Tenant ID
- Client Secret (Keep this value in a key vault and use it in the environment variable. For testing, you can keep it directly in the environment variable.)
- HOSTNAME
- SITE_PATH
Script highlight: Configuration section
const CLIENT_ID = Server.SiteSetting.Get("CLIENT_ID");
const CLIENT_SECRET = Server.SiteSetting.Get("CLIENT_SECRET");;
const TENANT_ID = Server.SiteSetting.Get("TENANT_ID");
const HOSTNAME = Server.SiteSetting.Get("HOSTNAME");
const SITE_PATH = Server.SiteSetting.Get("SITE_PATH");
These are securely loaded from Power Pages site settings (environment variables).
Step 6: Test the SharePoint integration
The script processes event registration form submissions, acquires a Microsoft Graph access token, generates an HTML ticket, uploads it to SharePoint, and creates a record in Dataverse.
Script highlight: Calling Microsoft Graph for access token
async function getAccessToken() {
const body = {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"scope": "https://graph.microsoft.com/.default",
"grant_type": "client_credentials"
};
const tokenResp = await Server.Connector.HttpClient.PostAsync(
`https://login.microsoftonline.com/${TENANT_ID}/oauth2/v2.0/token`,
JSON.stringify(body),
{ "Content-Type": "application/x-www-form-urlencoded" },
"application/x-www-form-urlencoded"
);
const tokenJson = JSON.parse(JSON.parse(tokenResp).Body);
return tokenJson.access_token;
}
Script highlight: Uploading ticket to SharePoint
const siteResp = await Server.Connector.HttpClient.GetAsync(
`https://graph.microsoft.com/v1.0/sites/${HOSTNAME}:${SITE_PATH}`,
{ Authorization: `Bearer ${accessToken}` }
);
const siteId = JSON.parse(JSON.parse(siteResp).Body).id;
const driveResp = await Server.Connector.HttpClient.GetAsync(
`https://graph.microsoft.com/v1.0/sites/${siteId}/drive`,
{ Authorization: `Bearer ${accessToken}` }
);
const driveId = JSON.parse(JSON.parse(driveResp).Body).id;
const uploadUrl = `https://graph.microsoft.com/v1.0/drives/${driveId}/root:/Tickets/${fileName}:/content`;
await Server.Connector.HttpClient.PutAsync(
uploadUrl,
htmlTicket,
{ Authorization: `Bearer ${accessToken}`, "Content-Type": "text/html" },
"text/html"
);
After a successful run:
- A new record appears in Dataverse under crd69_eventregistrations.
- An HTML ticket file is uploaded to your SharePoint Documents > Tickets folder.
- The crd69_ticketurl field contains the link to the uploaded ticket file.
(Optional) Step 7: Enable email notification
To send a confirmation email to the attendee:
- Uncomment the "Send confirmation email" section in the script.
- Replace {senderUserId} with a valid mailbox-enabled user ID (for example, a service account).
- Ensure Mail.Send permission is added and admin-consented.
Related information
Server logic overview
Author server logic
Server objects
How to interact with Dataverse tables using Server logic