> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/get-started/integrations/sharepoint/file-handler-app-with-graph-apis.md).

# File Handler App with Graph APIs

Integrate sharepoint pdf viewer for viewing, annotating, editing, and creating PDFs in Mendix. Process documents natively in Mendix without third-party applications.

Welcome to Apryse. This guide will help you **integrate a free trial of WebViewer into SharePoint Online as a web part**. It will help you clone the SharePoint sample repository and show you how to integrate WebViewer as a web part. Your free trial includes unlimited trial usage and support from solution engineers.

<a href="https://github.com/ApryseSDK/sharepoint-integration-examples/" class="button primary">Get the SharePoint sample source code here</a>

## Prerequisites

* [**Node** v22.21.0 **and NPM**](https://nodejs.org/en/blog/release/v22.21.0)
* SPFx: [v1.21.1](https://learn.microsoft.com/en-us/sharepoint/dev/spfx/release-1.21)
* WebViewer:

{% @apryse-download-button/apryse-download-button id="WebViewer\_web\_web" title="Download WebViewer" showVersion="true" %}

* (Optional but recommended) [**Node Version Manager**](http://npm.github.io/installation-setup-docs/installing/using-a-node-version-manager.html)
* Get your Apryse trial key.

{% @apryse-license-key/apryse-license-key platform="WEB\_VIEWER" variant="full" %}

For step-by-step help on setting up a SharePoint development environment, see one of the following:

* [SharePoint DX Setup Guide](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview/)
* [Set up your Microsoft 365 Tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant/)
* [Set up your SharePoint Framework Development Environment](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment/)

{% hint style="info" %}
**License Key Required**

The trial of Apryse SDK requires a trial license key, which is provided in the box titled "License Key". A commercial license key is required for use in a production environment. Please [contact sales](https://apryse.com/form/contact-sales) to purchase a commercial key or if you need any other license key assistance.
{% endhint %}

{% hint style="warning" %}
**Keep your license keys confidential.**

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
{% endhint %}

## SharePoint File Handler

[File handlers](https://docs.microsoft.com/en-us/onedrive/developer/file-handlers/) are an Microsoft 365 add-in that allows user to define customized actions on specified file types. With File Handlers, you can enable the following user experience:

* Create new files in the browser
* File preview
* Custom actions that launch into your app

### Create a helper app

You can started with creating a helper app that assist you to register the File Handler app in Azure Active Directory.

1. Sign in to Azure Portal

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-40a6ed3e442d48313ce11b3325711f4e12c99b46%2Fe5151e59d35a23b5c7df0c8fe9cfd1d25bbba3aa-3024x1564.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-af95834330b047a829a8352519f0de95deee09f6%2F3a5b925e0d06f93af220394a991094a0c0bba3f2-3024x1482.png?alt=media)

1. Select **App Registrations** on the left panel and click **+ New Registration**. Fill in a name that you would find it easily. We put **webviewer-helper** and click **Register**.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-be3d885757ec664aaf4e2f80bcf288fc866473ac%2Fcc868481cd510badb817f4767fad26289e6a51c7-3023x1435.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-6897f9b5f719e9a994ac0693431c0696c427e8d7%2F8a62e19399cb4012c840aebaf465f04be2bdfa61-3024x1478.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-508eba3c3f39e37d1be0834099660f3e04b1c2a6%2F98f0a093d1239413e5e755939b4f9803d17a2cf7-3024x1560.png?alt=media)

1. Select **API Permissions** on the left panel and click **Add a permission**.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f4f308176a4ede13f1c8a6f0d809521386ad85e6%2Fc41eb3b0f8e956d3a1abdc6addd1046c3cc12ecb-3024x1482.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-181da1e873ad60a29ed8b28844fd07ad34fc796a%2F422bb6d3c9cd656e6e276ce2ecaaaadc629eaee5-3024x1478.png?alt=media)

1. Select **Microsoft Graph** and **Delegated permissions**.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-2a224602e45249ab834ae6ec6b2bdcec35fbc46c%2F3f2add5de0ac0b0cb25013e987522245517d1e3e-3024x1478.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f0a5666ded3a1757aec339f87d95c7788f5827ee%2F4f5588e98aaf39a3e5445a6d34df4e2d055bfc17-3024x1480.png?alt=media)

1. Search for **Directory** and select **Directory.AccessAsUser.All**. Then search **openid** and select **openid**. Click **Add Permissions** after the permissions are selected.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-e40377aa589e2759cce7e0a9e8e677986d5c8c17%2F0ee417488ac883986c6dd6185769fecdb00ec193-1714x1480.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-34bbb8ecdc2280b0c408c57a21eb150db9565639%2F99c3c24393e4f07e005d431a5c9e2a95e861aa52-1712x1478.png?alt=media)

1. Grant admin consent if needed.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-c4466990184eae84cad3a51df1ddd2a23f1a8c52%2Fcf27aafcecf3fbc3b8a98a2e45c1cd45c007d19e-3024x1478.png?alt=media)

1. Select **Authentication** on the left panel, click **Add a platform** and select **Mobile and desktop applications**.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-a8b32064f22d2cebddb61c20e12c07a9decd774d%2F4dc54ac88f3ffff44a40710b679d312cef483139-3024x1478.png?alt=media)

1. Select the **MSAL only** for the Redirect URIs.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-f1865240d4fc39ca6226ba842d7be15ee05065a2%2F771c88c08aed81ec7e3d249fd0e1839453bf1a2d-3024x1480.png?alt=media)

1. Select **Yes** in **Allow public client flows** and click **Save**.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-4b356f08a5612f34b59a5932ab8641afd8295fb3%2Fa0602af5f27ca92d886cb520717ce7494b254a1b-3024x1480.png?alt=media)

### Project Setup

1. Git clone from the repository: [https://github.com/ApryseSDK/webviewer-filehandler](https://github.com/ApryseSDK/webviewer-filehandler/)

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
git clone https://github.com/ApryseSDK/webviewer-filehandler.git
```

{% endcode %}
{% endtab %}
{% endtabs %}

1. Run `npm run setup:dev` to start setting up app registration for the Webviewer File handler demo. In the terminal, Enter the **client id** and **tenant id** of the helper app when prompted. You could access the **client id** and **tenant id** in the **webviewer-app** in Azure Active Directory.

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
npm run setup:dev
```

{% endcode %}
{% endtab %}
{% endtabs %}

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-fc77d69d9b6368efcd45ad1dba969710b48144c7%2F69d153d5aca27128b68c4a7760e3e82a094292fe-3024x1478.png?alt=media)

1. The terminal should provide a link for you to enter verification code from Microsoft. Open the link in the browser and enter the given code.
2. A `.env` file should be created in the project root folder when the app registration is done. It should contain the following parameter:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
TENANT_ID=
CLIENT_ID=
CLIENT_SECRET=
FILE_HANDLER_SITE_HOST_URL=
```

{% endcode %}
{% endtab %}
{% endtabs %}

1. Run `npm run start:dev` to start the local server.

### Resetting cache in SharePoint

It usually takes about 24 - 48 hours for the new file handler to be effective in Sharepoint. However, microsoft provides a API to refresh the cache. ([Resetting the file handler cache](https://docs.microsoft.com/en-us/onedrive/developer/file-handlers/reset-cache?view=odsp-graph-online))

In order to get the access token for resetting Sharepoint cache, we can start from getting the code. Before using the API, we need to enable it in the **API permissions** under the application we registered (In this case, it's "Webviewer Demo").

1. Go to **Azure Active Directory** and select the application we registered.
2. Select **API permissions** on the left sidebar and click **+ Add a permission**. In **Request API permissions**, select **Sharepoint -> Application permissions -> Sites.ReadWrite.All**, and add the permission.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-cd28f4dc45bb6ee06d320a932b78149625edd52f%2Fbb40c32203d9126b2ccd1988b4bd01940e0c9462-3024x1482.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-c234b6a8a14ac5e4b9d74384922ca9645e7de2fd%2F4cac0d28fc57315cc433c8c77f2533288ebe200f-3024x1478.png?alt=media)

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-eeb6f419b04c3eeb3e5311ceebe223ce29a415c0%2Fc5b7774b261165176e32de6bb7cd47a008c10fac-3024x1480.png?alt=media)

1. If necessary, grand admin consent for the permissions.
2. Direct to `http://localhost:3000/app-reset-cache`. You'll be requested to login twice with your microsoft account during the process. Once it's reset successfully, you will see `Successfully reset the cache` on the page.

### Deployment in production

After the development, you may want to deploy your server and redirect the filehandler to the hosted server.

You can achieve this by change the **Manifest** in your application.

Change the `logoutUrl` with your new domain but with the same path. Change the `url` in the object of the array `replyUrlsWithType`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/get-started/integrations/sharepoint/file-handler-app-with-graph-apis.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
