D365: Call SharePoint API from plugin/custom workflow C# – Part 1

In this series of post, we’ll see how we can call SharePoint API from plugin or custom workflow using C# to retrieve number of documents uploaded to SharePoint for a particular record, albeit we can do any other operation connecting to SharePoint API.

To use SharePoint API, we need to create an Application in SharePoint and give it appropriate permission like we do in Azure Active Directory for Server to Server authentication.

In Part 1, we’ll see how we can create an Application in SharePoint and give it necessary permission.

In Part 2, we’ll see how to use details of the created Application to call SharePoint API.

Pre-requisites: SharePoint site has been created and configured for Document Management on CE instance.

Below are the steps to create app in SharePoint:

Go to https://SHAREPOINTDOMAINNAME.sharepoint.com/sites/SITENAME/_layouts/15/appregnew.aspx
For Client Id and Client Secret: Click Generate
Title: any name that you want to give
App Domain: any sample domain e.g. http://www.google.com
Redirect URL: https://localhost

After filling the details, Click Create

The summary of the app will be shown on the next screen. Keep Client ID and Client Secret handy as we will use these to connect to SharePoint API.

Now, we need to give the permission to the application created.
Go to https://SHAREPOINTDOMAINNAME.sharepoint.com/sites/SITENAME/_layouts/15/appinv.aspx
Populate the Client ID from the above step and click Lookup. This should fill the rest of the fields as per the details provided while creating the app.
For permission XML, use below XML.

<AppPermissionRequests AllowAppOnlyPolicy="true">
  <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl"/>
</AppPermissionRequests>

Once done, Click Create and now we are ready to call SharePoint API using Client ID and Client secret of this app which we’ll see in the next post.

Hope it helps !!


Advertisement

4 thoughts on “D365: Call SharePoint API from plugin/custom workflow C# – Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.