File tree 4 files changed +82
-0
lines changed
integration-templates/sharepoint-online
4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ import type { NangoAction , FetchFile , FetchFileInput } from '../../models' ;
2
+ import type { SharepointFetchFile } from '../types' ;
3
+
4
+ /**
5
+ * Fetches the latest file download URL from SharePoint, which can be used to download the actual file by making an XMLHttpRequest.
6
+ * @param nango - The NangoAction instance used to interact with the external API.
7
+ * @param input - Object containing siteId and itemId.
8
+ * @returns A Promise that resolves with the FetchFile.
9
+ */
10
+ export default async function runAction ( nango : NangoAction , input : FetchFileInput ) : Promise < FetchFile > {
11
+ validate ( nango , input ) ;
12
+
13
+ const response = await nango . get < SharepointFetchFile > ( {
14
+ endpoint : `/v1.0/sites/${ input . siteId } /drive/items/${ input . itemId } ` ,
15
+ params : {
16
+ select : 'id, @microsoft.graph.downloadUrl'
17
+ }
18
+ } ) ;
19
+
20
+ return {
21
+ id : response . data . id ,
22
+ download_url : response . data [ '@microsoft.graph.downloadUrl' ] ?? null
23
+ } ;
24
+ }
25
+
26
+ /**
27
+ * Validates the input to ensure it contains the required fields.
28
+ * @param nango - The NangoAction instance used for error handling.
29
+ * @param input - The input to validate.
30
+ */
31
+ function validate ( nango : NangoAction , input : FetchFileInput ) {
32
+ if ( ! input . siteId ) {
33
+ throw new nango . ActionError ( {
34
+ message : 'Missing required parameter: siteId'
35
+ } ) ;
36
+ }
37
+
38
+ if ( ! input . itemId ) {
39
+ throw new nango . ActionError ( {
40
+ message : 'Missing required parameter: itemId'
41
+ } ) ;
42
+ }
43
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,16 @@ integrations:
10
10
- offline_access
11
11
output : SharePointMetadata
12
12
version : 1.0.0
13
+ fetch-file :
14
+ description : |
15
+ This action will be used to fetch the latest file download_url which can be used to download the actual file.
16
+ endpoint : GET /sharepoint/fetch-file
17
+ scopes :
18
+ - Sites.ReadWrite.All
19
+ - offline_access
20
+ output : FetchFile
21
+ input : FetchFileInput
22
+ version : 1.0.0
13
23
syncs :
14
24
file-sync :
15
25
description : |
@@ -45,3 +55,9 @@ models:
45
55
webUrl : string
46
56
SharePointMetadata :
47
57
sitesToSync : Site[]
58
+ FetchFileInput :
59
+ siteId : string
60
+ itemId : string
61
+ FetchFile :
62
+ id : string
63
+ download_url : string | null
Original file line number Diff line number Diff line change @@ -225,3 +225,9 @@ export interface DriveItem {
225
225
webDavUrl ?: string ;
226
226
webUrl ?: string ;
227
227
}
228
+
229
+ export interface SharepointFetchFile {
230
+ '@odata.context' : string ;
231
+ id : string ;
232
+ '@microsoft.graph.downloadUrl' ?: string ;
233
+ }
Original file line number Diff line number Diff line change @@ -2725,6 +2725,17 @@ integrations:
2725
2725
- offline_access
2726
2726
output : SharePointMetadata
2727
2727
version : 1.0.0
2728
+ fetch-file :
2729
+ description : >
2730
+ This action will be used to fetch the latest file download_url which
2731
+ can be used to download the actual file.
2732
+ endpoint : GET /sharepoint/fetch-file
2733
+ scopes :
2734
+ - Sites.ReadWrite.All
2735
+ - offline_access
2736
+ output : FetchFile
2737
+ input : FetchFileInput
2738
+ version : 1.0.0
2728
2739
syncs :
2729
2740
file-sync :
2730
2741
description : >
@@ -2761,6 +2772,12 @@ integrations:
2761
2772
webUrl : string
2762
2773
SharePointMetadata :
2763
2774
sitesToSync : Site[]
2775
+ FetchFileInput :
2776
+ siteId : string
2777
+ itemId : string
2778
+ FetchFile :
2779
+ id : string
2780
+ download_url : string | null
2764
2781
slack :
2765
2782
syncs :
2766
2783
users :
You can’t perform that action at this time.
0 commit comments