small fix

This commit is contained in:
shraddha shaligram
2020-06-16 10:28:22 -07:00
5 changed files with 112 additions and 16 deletions

View File

@@ -376,7 +376,7 @@ export const taskFields = [
'Flag indicating whether hidden tasks are returned in the result'
},
{
displayName: 'updated Min',
displayName: 'Updated Min',
name: 'updatedMin',
type: 'string',

View File

@@ -1,4 +1,7 @@
import { OptionsWithUri } from 'request';
import {
OptionsWithUri,
} from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
@@ -6,17 +9,16 @@ import {
ILoadOptionsFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
import {
IDataObject,
} from 'n8n-workflow';
export async function webflowApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('webflowApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const authenticationMethod = this.getNodeParameter('authentication', 0);
let options: OptionsWithUri = {
headers: {
authorization: `Bearer ${credentials.accessToken}`,
'accept-version': '1.0.0',
},
method,
@@ -31,14 +33,22 @@ export async function webflowApiRequest(this: IHookFunctions | IExecuteFunctions
}
try {
return await this.helpers.request!(options);
} catch (error) {
if (authenticationMethod === 'accessToken') {
const credentials = this.getCredentials('webflowApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
let errorMessage = error.message;
if (error.response.body && error.response.body.err) {
errorMessage = error.response.body.err;
options.headers!['authorization'] = `Bearer ${credentials.accessToken}`;
return await this.helpers.request!(options);
} else {
return await this.helpers.requestOAuth2!.call(this, 'webflowOAuth2Api', options);
}
throw new Error('Webflow Error: ' + errorMessage);
} catch (error) {
if (error.response.body.err) {
throw new Error(`Webflow Error: [${error.statusCode}]: ${error.response.body.err}`);
}
return error;
}
}

View File

@@ -34,7 +34,25 @@ export class WebflowTrigger implements INodeType {
{
name: 'webflowApi',
required: true,
}
displayOptions: {
show: {
authentication: [
'accessToken',
],
},
},
},
{
name: 'webflowOAuth2Api',
required: true,
displayOptions: {
show: {
authentication: [
'oAuth2',
],
},
},
},
],
webhooks: [
{
@@ -45,6 +63,23 @@ export class WebflowTrigger implements INodeType {
},
],
properties: [
{
displayName: 'Authentication',
name: 'authentication',
type: 'options',
options: [
{
name: 'Access Token',
value: 'accessToken',
},
{
name: 'OAuth2',
value: 'oAuth2',
},
],
default: 'accessToken',
description: 'Method of authentication.',
},
{
displayName: 'Site',
name: 'site',