Showing posts with label SPFX. Show all posts
Showing posts with label SPFX. Show all posts

Wednesday, June 17, 2026

Integrating AI API with SPFx Web Part

AI is becoming an important part of modern applications. One useful use case in SharePoint is connecting AI APIs inside an SPFx web part.

This post will explain at high level ,how we can connect an AI API with an SPFx web part and create a simple 'Document Summary' solution.


Solution Architecture


Process
  1. SPFx web part reads document content from SharePoint
  2. Document content is sent securely to AI API
  3. AI service generates summary of the document
  4. SPFx web part displays summary to the user
Technology Stack
  • SharePoint Framework (React + TypeScript)
  • Microsoft SharePoint Online
  • REST API or Microsoft Graph API
  • AI API such as OpenAI, Azure OpenAI, or custom AI service
  • Azure Function or Backend API for secure communication

Frontend – SPFx Web Part


Read Document Content

The SPFx web part can read document content using SharePoint APIs/ PnP / Graph APIs.

Example:

const apiUrl = `${webAbsoluteUrl}/_api/web/GetFileByServerRelativeUrl('${fileUrlEncoded}')/$value`;

const response = await context.spHttpClient.get( apiUrl, SPHttpClient.configurations.v1 );

const content = <get text content from response based on different file type>


Calling AI API

After reading the document content, send it to AI service.

Example:

let headers = {
    'Content-Type': 'application/json'
};

headers.Authorization = `Bearer ${openAiKey}`;

let requestBody = {
    messages: [
        { 
        role: 'system', 
        content: 'You are a helpful summarization assistant.' 
        },
        { 
        role: 'user', 
        content: `Summarize this document. Document text:\n${content}` 
        }
    ],
    max_tokens: <maxTokens>
};

requestBody.model = <model>;

const result = await fetch(apiUrl, {
    method: "POST",
    headers,
    body: JSON.stringify(requestBody)
});

const summary = await result.json();

The AI service will process the document and return the summary.


Security Consideration

Do not keep API keys directly inside frontend code.

Recommended approach:

  • SPFx sends request to Azure API or Azure Function
  • Backend stores API key securely
  • Backend calls AI provider
  • Response is returned back to SPFx web part

This helps in protecting API keys and keeps the solution secure.


Conclusion

Integrating AI APIs with SPFx web parts can make SharePoint applications smarter and more useful. The future of SharePoint development is AI-powered intelligent solutions.

Sunday, December 28, 2025

SharePoint Online + Acumatica Integration Architecture (Using SPFx & OAuth2)

Modern SPFx + OAuth2 + Acumatica ERP Integration

Integrating SharePoint Online with Acumatica ERP allows organizations to bring core ERP data—such as Stock Items, Customers, Vendors, Sales Orders, and Cases—directly into a modern SPFx web part. This post shows how authentication, tokens, and data flows work together in a secure enterprise-ready design.


🌐 High-Level Architecture

The following diagram shows the full end-to-end architecture:


Figure 1 — SharePoint–Acumatica Integration Architecture


1️⃣ Solution Overview

The SPFx web part enables users to:

  • Filter and browse Acumatica entities
  • Select entity items and display fields in real time
  • Optionally save entity fields into a SharePoint list
  • Work with either cached or live ERP data

2️⃣ Architecture Components

🔹 SharePoint Online

  • Hosts SPFx UI
  • Stores selected entity data in lists
  • Authenticates via Microsoft Entra ID (MSAL)

🔹 SPFx Web Part

  • React-based UI
  • Calls backend API using access token
  • Stores access + refresh tokens
  • Displays live or saved Acumatica data

🔹 Integration API (Azure Function / App Service)

  • Handles authentication to Acumatica
  • Stores and refreshes tokens
  • Executes REST calls securely

🔹 Acumatica ERP

  • Exposes REST API
  • Supports OAuth2 & Azure AD SSO
  • Returns requested entities

3️⃣ Authentication Flows

Three authentication models can be used depending on business and security needs.

🔵 Flow A: Service Account (Admin Credentials)

A backend service account authenticates to Acumatica and returns ERP data to SharePoint. This is easiest for read-only, system-level operations.

🟢 Flow B: User Credentials (OAuth 2.0 Authorization Code)

Users enter their Acumatica credentials. Access token is issued per user, respecting their permissions in Acumatica.

🟣 Flow C: Azure AD SSO (Recommended)

Provides seamless login between SharePoint and Acumatica using the same Entra ID identity.


4️⃣ Token Lifecycle

SPFx stores and uses the following:

  • Access Token
  • Refresh Token
  • Expiry Time

When the access token expires, the refresh token is used to obtain a new one automatically. No user interaction needed.


5️⃣ Data Delivery Modes

🔹 Local Mode (Cached Data)

  • Selected entity fields saved in SharePoint list
  • Fast page load
  • Best for stable master-data

🔹 Live Mode (Real-Time API Calls)

  • Data fetched from Acumatica on every page load
  • No duplication of ERP data in SharePoint
  • Ideal for dynamic data (orders, quantities, QC updates)

6️⃣ High-Level Data Flow

  1. User opens the SharePoint page
  2. SPFx authenticates using MSAL
  3. SPFx queries the Integration API
  4. API manages token lifecycle
  5. Acumatica returns requested entity data
  6. SPFx outputs or stores the data

7️⃣ Why This Architecture Works

  • Secure (OAuth2 + Azure AD)
  • No credentials stored client-side
  • Supports real-time and cached modes
  • Scalable using Azure Functions
  • Works with enterprise SSO


Part 1 - Acumatica Files -> SharePoint DMS Integration

Part 2 - SharePoint DMS -> Acumatica Files Integration

Thursday, December 25, 2025

Acumatica - SharePoint DMS Integration
SPFx Library Extension + Approval Workflow

SharePoint–Acumatica DMS Integration — SPFx Library Extension

SharePoint Online is a powerful DMS (versioning, metadata, workflows). Acumatica is the ERP system of record. This integration routes documents through SharePoint libraries, enforces approval and metadata, and only publishes validated documents into Acumatica.


Overview

A custom SPFx Library Extension adds two actions to document libraries:

  • Get From Acumatica — Fetch attachments from Acumatica into the current library.
  • Publish to Acumatica — Push approved SharePoint files into Acumatica as attachments.

All uploaded files are routed through the SharePoint library, reviewed via an approval workflow, and only published to Acumatica after approval—ensuring governance and auditability.


How It Works

Step 1 — Upload & Metadata

When a user uploads a file, default metadata is applied automatically:

  • Entity Type (Customer, Vendor, Order, Project, etc.)
  • Entity ID
  • Document Category
  • Status = Draft

Step 2 — Approval Workflow

A Power Automate approval flow handles reviewer assignment, notifications and status changes. Only when the file is Approved does the Publish to Acumatica action become available.

Step 3 — Publish to Acumatica

  1. SPFx extension invokes the Integration API (Azure Function / App Service)
  2. API authenticates with Acumatica (OAuth2 / SSO)
  3. File binary + metadata are posted to Acumatica and attached to the correct entity
  4. SharePoint status updated to Published and audit log saved

Reverse Sync — Get From Acumatica

The extension can also pull attachments from Acumatica to SharePoint. Workflow:

  • Select entity in the UI
  • Click Get From Acumatica
  • Attachments are downloaded to the current folder with mapped metadata

Architecture (High-level)

Key components:

  • SharePoint Online Library — storage, metadata, versioning
  • SPFx Library Extension — UI actions, client logic
  • Power Automate — approval workflows
  • Integration API (Azure) — token handling, Acumatica calls
  • Acumatica REST API — attachments & entity metadata
Figure — SharePoint to Acumatica DMS Integration (high-level)

SPFx Library Extension

The SPFx Library Extension is the core interaction layer embedded directly within the SharePoint document library. It provides contextual actions and communicates with Acumatica in real time.

  • Get From Acumatica – Fetch documents or metadata from Acumatica into SharePoint.
  • Publish to Acumatica – Publish approved files directly to Acumatica using REST APIs.

Authentication is handled using either:

  • Azure AD access token (recommended)
  • Stored Acumatica OAuth token (where required)

Power Automate

Power Automate is intentionally kept minimal and focused only on business approvals.

  • Used exclusively for approval workflows
  • No publishing or integration logic

Once the approval is completed:

  • File status is updated to Approved
  • The Publish to Acumatica action becomes available in the SPFx extension

Azure Function (Optional)

An Azure Function can be introduced if additional security or backend validation is required.

Typical use cases include:

  • IP-restricted Acumatica environments
  • Backend token handling
  • Additional validation or logging

If Acumatica allows direct client-to-API communication, this layer can be skipped.


End-to-End Flow

The overall document flow is simple, auditable, and approval-driven:

  1. User uploads a document to the SharePoint Library
  2. Approval workflow runs via Power Automate
  3. After approval, SPFx Extension enables publishing
  4. SPFx Extension calls Acumatica REST API (directly or via Azure Function)

User → SharePoint Library → SPFx Extension → (Optional Azure Function) → Acumatica REST API



Business Benefits

  • Governance: Only approved documents reach ERP.
  • Consistency: Metadata normalization for better search & reporting.
  • Auditability: Version history, approver details and workflow logs.
  • Process Control: Centralized ingestion point for all company uploads.
  • Compliance: Documents validated before ERP consumption.
  • Clear separation of concerns
  • Secure and governed document publishing
  • No unnecessary backend dependency
  • Better user experience within SharePoint

Common Use Cases

  • Invoice and Finance document validation before publish
  • Purchase / Sales attachments (POs, Delivery Notes)
  • QC Reports and Certificates—approved prior to upload
  • Vendor and Customer contract lifecycle management
  • Project documentation and technical drawings

Implementation Notes

  • Security: Keep credentials & tokens in a secure server-side store. Do not store refresh tokens in browser localStorage.
  • API: Integration API should handle retries, throttling and token refresh.
  • UX: Display publish status and last-synced timestamp on the file card.
  • Audit: Log every publish and retrieval action with user context for compliance.

Conclusion

Making SharePoint the document gateway for Acumatica provides strong governance, better collaboration, and a single controlled ingestion point. By using SPFx library extensions, Power Automate approval workflows, and a secure integration API, organizations ensure only validated, metadata-rich documents enter the ERP—reducing errors and improving compliance.


Part 2 - SharePoint DMS -> Acumatica Files Integration

Part 3 - Acumatica Entity -> SharePoint List/Pages Integration