mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
feature/outlook shared mailbox (#1323)
* ⚡ Add shared mailbox support * 🐛 Add filter field to folderMessage:getAll * ⚡ Small changes to descriptions (#1322) Co-authored-by: Mika Luhta <12100880+mluhta@users.noreply.github.com>
This commit is contained in:
parent
76cee5577b
commit
d78aaa2d64
|
@ -16,7 +16,27 @@ export class MicrosoftOutlookOAuth2Api implements ICredentialType {
|
||||||
displayName: 'Scope',
|
displayName: 'Scope',
|
||||||
name: 'scope',
|
name: 'scope',
|
||||||
type: 'hidden' as NodePropertyTypes,
|
type: 'hidden' as NodePropertyTypes,
|
||||||
default: 'openid offline_access Mail.ReadWrite Mail.Send MailboxSettings.Read',
|
default: 'openid offline_access Mail.ReadWrite Mail.ReadWrite.Shared Mail.Send Mail.Send.Shared MailboxSettings.Read',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Use Shared Mailbox',
|
||||||
|
name: 'useShared',
|
||||||
|
type: 'boolean' as NodePropertyTypes,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'User Principal Name',
|
||||||
|
name: 'userPrincipalName',
|
||||||
|
description: 'Target user\'s UPN or ID',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
useShared: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,7 +251,7 @@ export const folderFields = [
|
||||||
name: 'filter',
|
name: 'filter',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Microsoft Graph API OData $filter query.',
|
description: 'Microsoft Graph API OData $filter query. Information about the syntax can be found <a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter" target="_blank">here</a>.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -115,7 +115,7 @@ export const folderMessageFields = [
|
||||||
name: 'filter',
|
name: 'filter',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Microsoft Graph API OData $filter query.',
|
description: 'Microsoft Graph API OData $filter query. Information about the syntax can be found <a href="https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter" target="_blank">here</a>.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,6 +14,14 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = { json: true }): Promise<any> { // tslint:disable-line:no-any
|
export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, headers: IDataObject = {}, option: IDataObject = { json: true }): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
const credentials = this.getCredentials('microsoftOutlookOAuth2Api');
|
||||||
|
|
||||||
|
let apiUrl = `https://graph.microsoft.com/v1.0/me${resource}`;
|
||||||
|
// If accessing shared mailbox
|
||||||
|
if (credentials!.useShared && credentials!.userPrincipalName) {
|
||||||
|
apiUrl = `https://graph.microsoft.com/v1.0/users/${credentials!.userPrincipalName}${resource}`;
|
||||||
|
}
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -21,7 +29,7 @@ export async function microsoftApiRequest(this: IExecuteFunctions | IExecuteSing
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs,
|
qs,
|
||||||
uri: uri || `https://graph.microsoft.com/v1.0/me${resource}`,
|
uri: uri || apiUrl,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
Object.assign(options, option);
|
Object.assign(options, option);
|
||||||
|
|
|
@ -926,6 +926,10 @@ export class MicrosoftOutlook implements INodeType {
|
||||||
qs['$select'] = additionalFields.fields;
|
qs['$select'] = additionalFields.fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (additionalFields.filter) {
|
||||||
|
qs['$filter'] = additionalFields.filter;
|
||||||
|
}
|
||||||
|
|
||||||
const endpoint = `/mailFolders/${folderId}/messages`;
|
const endpoint = `/mailFolders/${folderId}/messages`;
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await microsoftApiRequestAllItems.call(
|
responseData = await microsoftApiRequestAllItems.call(
|
||||||
|
|
Loading…
Reference in a new issue