How to integrate Sharepoint with Bonita

Sharepoint integration example

This article will help you explore one of the possible ways to integrate your Bonita applications with Microsoft 365, using Graph API. 

Microsoft Graph is a single endpoint, providing access to data and services in the Microsoft cloud. It exposes REST APIs to access data on Microsoft 365 services like OneDrive, Outlook, Sharepoint, Team etc. You can use it on all different kinds of applications that will let you handle meetings based on process tasks, generate Excel files in your OneDrive with the data handled by your processes, and so on.

In this example, we focus on the Sharepoint integration and we will highlight only the main steps. For all other scenarios and details, check out the Graph documentation.

Note: you can get an instant sandbox pre-configured with sample data if you join Microsoft 365 Developer Program (free renewable 90-day subscription), including Sharepoint.

 

Authentication and authorization
 

To call Microsoft Graph, your application should first generate an access token from the Microsoft identity platform. Access tokens will contain information used to validate the caller and to ensure that the caller has proper permissions to perform the operation requested. There are different types of permissions: application and delegated. Choose the one most suitable for your needs. In our example, we use the application permission, as we don’t need to act on behalf of a specific user.

Before you can request a token, your application must be registered in the Azure portal.
Go to Azure Active Directory and choose App registrations. Create a New registration, provide a new name for your application and select the account type.

For your newly registered application, you then need to expose an API (add a scope and authorized client application using its Client ID).

Then, you need to add API permissions. It is a good practice to add only the permissions that you need, to limit security risks, and decide whether only Read permissions would be enough for certain objects or if you need to give ReadWrite access. You can use the online Graph Explorer to help you determine which permissions you need to add. You can execute sample queries and it will show you the list of permissions used.

 

 

REST API connector configuration

Generate token

use the POST connector and generate a token that you can then use for other actions.

The URL to call is:

https://login.microsoftonline.com/' + sharepointTenant +'/oauth2/v2.0/token

where sharepointTenant should contain your tenant name (such as abcdef.microsoft.com).

Use application/x-www-form-urlencoded as the Content Type, and your Payload could be as follows:

'grant_type=client_credentials&client_id='+ azureClientID + '&client_secret='+ azureClientSecret +'&scope=https://graph.microsoft.com/.default'

where:

  •  grant_type must contain “client_credentials”
  • client_id should contain the Application ID that you got while registering your application in Azure Portal
  • client_secret should contain the secret that you generated for your app.

Use the scope value from this example if you want to access all the application permissions that you have configured for your application in the portal.

You can parse the bodyAsString output of your connector in order to get the token and store it in a process variable or a parameter:

import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
def object = slurper.parseText(bodyAsString)
return object.access_token

 

Create folder

As described in the Graph documentation, there are different POST calls that you can make, depending on your use case. In this example, we want to create a new folder, using a call to:

/drives/{drive-id}/items/{parent-item-id}/children

Use application/json as a Content Type, and here is an example of a payload using Groovy script:

return '{"name": "'+ request.caseId.toString() +'",  "folder": {  },  "@microsoft.graph.conflictBehavior": "rename"}'


You need to add a header with a key “Authorization” and the value of the token that you previously generated (see above). It is helpful to save the name of the newly created folder so you can use it later on to upload documents to it.

 

Upload small files

If you want to upload files smaller than 4MB, you can use a PUT File connector with a url in this format:

/drives/{drive-id}/items/{parent-id}:/{filename}:/content

with application/octet-stream as a Content Type and selecting a process document from the drop-down list. Don’t forget the Authorization header.

For large files, you should use a resumable upload with a session. Find more information in the Graph REST documentation here.

 


For a detailed tutorial you can watch this Live Demo where we show how to integrate Bonita with Sharepoint on Youtube. 

This article can also be found on our documentation for you to read. If you have any feedbacks do not hesitate to leave a comment. I hope you find this article helpful. smiley