Skip to content

Commit e11e069

Browse files
feat(integration-template): add sharepoint fetch-file action (NangoHQ#2551)
## Describe your changes - Added a sharepoint `fetch-file` action that accepts `siteId` and `itemId` as inputs and returns the file id and latest `download_url`. ## Issue ticket number and link [EXT-113](https://linear.app/nango/issue/EXT-113/sharepoint-add-nango-action-to-download-a-file-with-an-update-access) ## Checklist before requesting a review (skip if just adding/editing APIs & templates) - [ ] I added tests, otherwise the reason is: - [ ] I added observability, otherwise the reason is: - [ ] I added analytics, otherwise the reason is:
1 parent 6a18514 commit e11e069

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

integration-templates/sharepoint-online/nango.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ integrations:
1010
- offline_access
1111
output: SharePointMetadata
1212
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
1323
syncs:
1424
file-sync:
1525
description: |
@@ -45,3 +55,9 @@ models:
4555
webUrl: string
4656
SharePointMetadata:
4757
sitesToSync: Site[]
58+
FetchFileInput:
59+
siteId: string
60+
itemId: string
61+
FetchFile:
62+
id: string
63+
download_url: string | null

integration-templates/sharepoint-online/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,9 @@ export interface DriveItem {
225225
webDavUrl?: string;
226226
webUrl?: string;
227227
}
228+
229+
export interface SharepointFetchFile {
230+
'@odata.context': string;
231+
id: string;
232+
'@microsoft.graph.downloadUrl'?: string;
233+
}

packages/shared/flows.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -2725,6 +2725,17 @@ integrations:
27252725
- offline_access
27262726
output: SharePointMetadata
27272727
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
27282739
syncs:
27292740
file-sync:
27302741
description: >
@@ -2761,6 +2772,12 @@ integrations:
27612772
webUrl: string
27622773
SharePointMetadata:
27632774
sitesToSync: Site[]
2775+
FetchFileInput:
2776+
siteId: string
2777+
itemId: string
2778+
FetchFile:
2779+
id: string
2780+
download_url: string | null
27642781
slack:
27652782
syncs:
27662783
users:

0 commit comments

Comments
 (0)