feat(Webflow Node): Update to use the v2 API (#9996)

This commit is contained in:
Jon
2024-08-07 10:18:05 +01:00
committed by GitHub
parent 15f10ec325
commit 6d8323fade
18 changed files with 1514 additions and 569 deletions

View File

@@ -6,6 +6,7 @@ import type {
IWebhookFunctions,
IHttpRequestMethods,
IRequestOptions,
INodePropertyOptions,
} from 'n8n-workflow';
export async function webflowApiRequest(
@@ -17,21 +18,9 @@ export async function webflowApiRequest(
uri?: string,
option: IDataObject = {},
) {
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken');
let credentialsType = '';
if (authenticationMethod === 'accessToken') {
credentialsType = 'webflowApi';
}
if (authenticationMethod === 'oAuth2') {
credentialsType = 'webflowOAuth2Api';
}
let credentialsType = 'webflowOAuth2Api';
let options: IRequestOptions = {
headers: {
'accept-version': '1.0.0',
},
method,
qs,
body,
@@ -40,6 +29,19 @@ export async function webflowApiRequest(
};
options = Object.assign({}, options, option);
// Keep support for v1 node
if (this.getNode().typeVersion === 1) {
console.log('v1');
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken');
if (authenticationMethod === 'accessToken') {
credentialsType = 'webflowApi';
}
options.headers = { 'accept-version': '1.0.0' };
} else {
options.resolveWithFullResponse = true;
options.uri = `https://api.webflow.com/v2${resource}`;
}
if (Object.keys(options.qs as IDataObject).length === 0) {
delete options.qs;
}
@@ -74,3 +76,50 @@ export async function webflowApiRequestAllItems(
return returnData;
}
// Load Options
export async function getSites(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const response = await webflowApiRequest.call(this, 'GET', '/sites');
console.log(response);
const sites = response.body?.sites || response;
for (const site of sites) {
returnData.push({
name: site.displayName || site.name,
value: site.id || site._id,
});
}
return returnData;
}
export async function getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const siteId = this.getCurrentNodeParameter('siteId');
const response = await webflowApiRequest.call(this, 'GET', `/sites/${siteId}/collections`);
const collections = response.body?.collections || response;
for (const collection of collections) {
returnData.push({
name: collection.displayName || collection.name,
value: collection.id || collection._id,
});
}
return returnData;
}
export async function getFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const collectionId = this.getCurrentNodeParameter('collectionId');
const response = await webflowApiRequest.call(this, 'GET', `/collections/${collectionId}`);
const fields = response.body?.fields || response;
for (const field of fields) {
returnData.push({
name: `${field.displayName || field.name} (${field.type}) ${field.isRequired || field.required ? ' (required)' : ''}`,
value: field.slug,
});
}
return returnData;
}