Sharepoint
SharePoint watcher is easy enough to setup and only requires the Graph authorization details.
The Watcher automatically polls for folder changes within a sharepoint library and gives you an SDK as well as a callback any time a new file is added or changed. You will also get the item in the callback if a field has been updated.
This allows for automated processes to be kicked off any time something within the watched SharePoint directory is modified.
Example Configuration
Here's the fully configured and ready to use snippet of setting this up within Perigee.
All of the above are referencing a node in the appsettings.json
file, you would need to fill this out with your own authorization details.
tenant/appID/appSecret - These will be pulled from the Azure portal app registration.
The drivePath supplied may be blank if you're pulling files from the root of the drive. Otherwise supply the name of the folder to watch.
The site key is the full address of the sharepoint site. It's used to perform a graph lookup of the ID records required.
The listName is the name of the list behind the drive. If using the default document library, this will be "
Documents
". If you've created a custom library, something like "Input", then you will need to set the listName to that instead.The enabled flag is to turn the process on or off and is tied to the
.LinkToConfig()
line above.
SDK & Callbacks
Sync Class - Callback Property
The sync
property sent back by the SharePoint watcher contains all of the relevant ID's needed to perform requests within SharePoint. Most importantly:
ListID
DriveID
SiteID
SiteName
Items
callback
Items
callbackWhen new items arrive to be processed, you'll get a list of those items in that callback. Each item in the list contains all of the properties you'd need to check the item that was changed.
To see the full list and response please check out the Microsoft documentation
Change Notification
Want to check if the changed notification is a file?
Get Item + Fields
This call retrieves the item from a drive, and expands the response to include the list detail and fields as well
The list fields are important as they allow you to get the custom field values. In this example, we have a custom field called "Status" that we can update along the process:
Get Item by Path
To get an item if you already have the path.
If expand is true, you'll also receive the list item details along with the response.
Get Item by Path In Drive
To get an item if you already have the path for a given DriveID.
If expand is true, you'll also receive the list item details along with the response.
Generate SharePoint Download Link
You can generate a direct download link to a SharePoint item by giving the Site, library, and path to the item.
The resulting string is generated and uses the SharePoint /Download.aspx
page.
Delete an Item
To remove an item by ID:
Patch a Field
After retrieving the List Details, you can patch any of the fields with the PatchField
command:
Get Another Drive
If you need to get a different drive, say a Processed drive, you can do so by querying for the drive:
Uploading an item
To upload an item to a drive you must supply the DriveID
, Name
, Content
, and MIME Type
.
We'll upload a document to the Processed drive as shown here.
Download an Item
To download an item from SharePoint we highly recommend first getting the List Details as well as it can provide a backup download link. Then simply call download:
Implementing your own
To call any other method not supplied here use the internal graph call client and supply the right path, the rest will be taken care of automatically.
Last updated