Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/gcsconsultores/centros-estrategicos-gcs/llms.txt

Use this file to discover all available pages before exploring further.

The SharePoint integration stores captured leads — contact name, email, company, and service interest — as items in a SharePoint List via the Microsoft Graph API. When a visitor fills out a contact form in any sala of the virtual office, the /api/leads route authenticates as a service principal using the OAuth2 client credentials flow, then writes the data directly to the configured list. The full column schema and Graph API request structure are documented below.

Required List Schema

Create a SharePoint List with the following columns. The Internal Name values must match exactly — these are the field keys sent by the Graph API in the fields object.
Internal NameTypeDescription
TitleSingle line of textContact full name (required, maps to the list’s built-in Title column)
EmailSingle line of textContact email address
EmpresaSingle line of textCompany name
TelefonoSingle line of textPhone number (optional)
ServicioChoiceService of interest (e.g. compliance, training, ejecutiva)
MensajeMultiple lines of textAdditional message from the contact
OrigenSingle line of textSource identifier (e.g. Oficina Virtual - Sala Ejecutiva)
FechaCreacionDate and TimeTimestamp of lead creation — set server-side in ISO 8601 format

Creating the List

1

Navigate to your SharePoint site

Go to your SharePoint site → Site ContentsNewList.
2

Create a blank list

Select Blank list and give it a name (e.g. GCS Leads). Click Create.
3

Add columns from the schema

For each row in the schema table above (except Title, which already exists), click + Add column and select the matching column type. Set the Internal Name (or column name) exactly as shown — SharePoint uses this as the field key in the Graph API.
4

Note the list ID

Copy the list ID from the URL while viewing the list settings, or retrieve it via the Microsoft Graph API as described in the Microsoft 365 setup guide.

Microsoft Graph API Flow

The /api/leads route performs a two-step sequence: first acquiring an access token using the OAuth2 client credentials grant, then POSTing the lead as a new list item.
// Step 1: Get OAuth2 token
const tokenUrl = `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`
const tokenResponse = await fetch(tokenUrl, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: new URLSearchParams({
    client_id: clientId,
    client_secret: clientSecret,
    scope: 'https://graph.microsoft.com/.default',
    grant_type: 'client_credentials',
  })
})
const { access_token } = await tokenResponse.json()

// Step 2: Create list item
const graphUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items`
await fetch(graphUrl, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${access_token}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    fields: {
      Title: nombre,
      Email: email,
      Empresa: empresa,
      Telefono: telefono,
      Servicio: servicio,
      Mensaje: mensaje,
      Origen: origen,
      FechaCreacion: new Date().toISOString(),
    }
  })
})
The token is fetched fresh on each request — there is no token caching in the current implementation. In high-volume scenarios, consider caching the token until its expires_in boundary to reduce latency.

MSGraphConfig Interface

The MSGraphConfig interface in lib/types.ts defines the shape of the configuration object used when constructing Microsoft Graph requests:
export interface MSGraphConfig {
  clientId: string;
  tenantId: string;
  clientSecret: string;
  siteId: string;   // SharePoint Site ID
  listId: string;   // SharePoint List ID for leads
}
All five fields map directly to the environment variables AZURE_AD_CLIENT_ID, AZURE_AD_TENANT_ID, AZURE_AD_CLIENT_SECRET, SHAREPOINT_SITE_ID, and SHAREPOINT_LIST_ID.

Required Environment Variables

AZURE_AD_CLIENT_ID=        # Application (client) ID from Azure AD
AZURE_AD_CLIENT_SECRET=    # Client secret value
AZURE_AD_TENANT_ID=        # Directory (tenant) ID
SHAREPOINT_SITE_ID=        # Target SharePoint site ID
SHAREPOINT_LIST_ID=        # Target SharePoint list ID
Test your SharePoint connection end-to-end by sending a POST request to /api/leads with a test payload from Postman or curl. A successful response includes storage: 'sharepoint' — confirm the item appears in your SharePoint list afterward. If credentials are missing or misconfigured, the response will return storage: 'local' instead of an error.
The Sites.ReadWrite.All permission grants read and write access to all SharePoint sites in your tenant, not just the one used by the virtual office. If your organization enforces least-privilege access policies, work with your SharePoint administrator to scope the app registration’s access to a specific site using SharePoint’s site-level permission grant feature.

Build docs developers (and LLMs) love