Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n8n-3935-node-improvement-pr-webflow-trigger #3594

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/WebflowApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateGeneric,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand All @@ -15,4 +17,18 @@ export class WebflowApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
'Authorization': '=Bearer {{$credentials.accessToken}}',
},
},
};
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.webflow.com',
url: '/sites',
},
};
}
23 changes: 12 additions & 11 deletions packages/nodes-base/nodes/Webflow/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import {
IDataObject,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';

export async function webflowApiRequest(
Expand All @@ -24,7 +23,17 @@ export async function webflowApiRequest(
uri?: string,
option: IDataObject = {},
) {
const authenticationMethod = this.getNodeParameter('authentication', 0);
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken');
let credentialsType = '';

if (authenticationMethod === 'accessToken') {
credentialsType = 'webflowApi';
}

if (authenticationMethod === 'oAuth2') {
credentialsType = 'webflowOAuth2Api';
}


let options: OptionsWithUri = {
headers: {
Expand All @@ -46,15 +55,7 @@ export async function webflowApiRequest(
delete options.body;
}
try {
if (authenticationMethod === 'accessToken') {
const credentials = await this.getCredentials('webflowApi');

options.headers!['authorization'] = `Bearer ${credentials.accessToken}`;

return await this.helpers.request!(options);
} else {
return await this.helpers.requestOAuth2!.call(this, 'webflowOAuth2Api', options);
}
return await this.helpers.requestWithAuthentication.call(this, credentialsType, options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
Expand Down
22 changes: 13 additions & 9 deletions packages/nodes-base/nodes/Webflow/WebflowTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,22 @@ export class WebflowTrigger implements INodeType {
default: {
async checkExists(this: IHookFunctions): Promise<boolean> {
const webhookData = this.getWorkflowStaticData('node');
const webhookUrl = this.getNodeWebhookUrl('default');
const siteId = this.getNodeParameter('site') as string;
if (webhookData.webhookId === undefined) {
return false;
}
const endpoint = `/sites/${siteId}/webhooks/${webhookData.webhookId}`;
try {
await webflowApiRequest.call(this, 'GET', endpoint);
} catch (error) {
return false;

const event = this.getNodeParameter('event') as string;
const registeredWebhooks = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/webhooks`) as IDataObject[];

for (const webhook of registeredWebhooks) {
if (webhook.url === webhookUrl && webhook.triggerType === event) {
webhookData.webhookId = webhook._id;
return true;
}
}
return true;

return false;
},

async create(this: IHookFunctions): Promise<boolean> {
const webhookUrl = this.getNodeWebhookUrl('default');
const webhookData = this.getWorkflowStaticData('node');
Expand Down