mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Improvements to Quick Base Node
This commit is contained in:
parent
4eed7bb9fb
commit
60be31d410
|
@ -13,13 +13,15 @@ export class QuickBaseApi implements ICredentialType {
|
||||||
name: 'hostname',
|
name: 'hostname',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
|
required: true,
|
||||||
placeholder: 'demo.quickbase.com',
|
placeholder: 'demo.quickbase.com',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'User Token',
|
displayName: 'User Token',
|
||||||
name: 'userToken',
|
name: 'userToken',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ export const fieldOperations = [
|
||||||
description: 'Get all fields',
|
description: 'Get all fields',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
default: 'create',
|
default: 'getAll',
|
||||||
description: 'The operation to perform.',
|
description: 'The operation to perform.',
|
||||||
},
|
},
|
||||||
] as INodeProperties[];
|
] as INodeProperties[];
|
||||||
|
|
|
@ -52,7 +52,7 @@ export const fileFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The table identifier',
|
description: 'The table identifier.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Record ID',
|
displayName: 'Record ID',
|
||||||
|
@ -71,7 +71,7 @@ export const fileFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The unique identifier of the record',
|
description: 'The unique identifier of the record.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Field ID',
|
displayName: 'Field ID',
|
||||||
|
|
|
@ -17,11 +17,15 @@ export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptions
|
||||||
|
|
||||||
const credentials = this.getCredentials('quickbaseApi') as IDataObject;
|
const credentials = this.getCredentials('quickbaseApi') as IDataObject;
|
||||||
|
|
||||||
if (credentials.hostname === '') {
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!credentials.hostname) {
|
||||||
throw new Error('Hostname must be defined');
|
throw new Error('Hostname must be defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credentials.userKey === '') {
|
if (!credentials.userToken) {
|
||||||
throw new Error('User Token must be defined');
|
throw new Error('User Token must be defined');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,14 +75,14 @@ export async function quickbaseApiRequest(this: IExecuteFunctions | ILoadOptions
|
||||||
export async function getFieldsObject(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, tableId: string): any {
|
export async function getFieldsObject(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, tableId: string): any {
|
||||||
const fieldsLabelKey: { [key: string]: number } = {};
|
const fieldsLabelKey: { [key: string]: number } = {};
|
||||||
const fieldsIdKey: { [key: number]: string } = {};
|
const fieldsIdKey: { [key: number]: string } = {};
|
||||||
const data = await quickbaseApiRequest.call(this, 'GET', '/fields', {}, { tableId });
|
const data = await quickbaseApiRequest.call(this, 'GET', '/fields', {}, { tableId });
|
||||||
for (const field of data) {
|
for (const field of data) {
|
||||||
fieldsLabelKey[field.label] = field.id;
|
fieldsLabelKey[field.label] = field.id;
|
||||||
fieldsIdKey[field.id] = field.label;
|
fieldsIdKey[field.id] = field.label;
|
||||||
}
|
}
|
||||||
return { fieldsLabelKey, fieldsIdKey };
|
return { fieldsLabelKey, fieldsIdKey };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function quickbaseApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function quickbaseApiRequestAllItems(this: IHookFunctions | ILoadOptionsFunctions | IExecuteFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
@ -125,7 +129,7 @@ export async function quickbaseApiRequestAllItems(this: IHookFunctions | ILoadOp
|
||||||
returnData.push.apply(returnData, responseData);
|
returnData.push.apply(returnData, responseData);
|
||||||
responseData = [];
|
responseData = [];
|
||||||
} while (
|
} while (
|
||||||
returnData.length < metadata.totalRecords
|
returnData.length < metadata.totalRecords
|
||||||
);
|
);
|
||||||
|
|
||||||
return returnData;
|
return returnData;
|
||||||
|
|
|
@ -42,7 +42,7 @@ export class QuickBase implements INodeType {
|
||||||
displayName: 'Quick Base',
|
displayName: 'Quick Base',
|
||||||
name: 'quickbase',
|
name: 'quickbase',
|
||||||
icon: 'file:quickbase.png',
|
icon: 'file:quickbase.png',
|
||||||
group: [ 'input' ],
|
group: ['input'],
|
||||||
version: 1,
|
version: 1,
|
||||||
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
||||||
description: 'Integrate with the Quick Base RESTful API.',
|
description: 'Integrate with the Quick Base RESTful API.',
|
||||||
|
@ -50,11 +50,12 @@ export class QuickBase implements INodeType {
|
||||||
name: 'Quick Base',
|
name: 'Quick Base',
|
||||||
color: '#73489d',
|
color: '#73489d',
|
||||||
},
|
},
|
||||||
inputs: [ 'main' ],
|
inputs: ['main'],
|
||||||
outputs: [ 'main' ],
|
outputs: ['main'],
|
||||||
credentials: [
|
credentials: [
|
||||||
{
|
{
|
||||||
name: 'quickbaseApi',
|
name: 'quickbaseApi',
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
@ -158,8 +159,8 @@ export class QuickBase implements INodeType {
|
||||||
const limit = this.getNodeParameter('limit', i) as number;
|
const limit = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
responseData = responseData.splice(0, limit);
|
responseData = responseData.splice(0, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
returnData.push.apply(returnData, responseData);
|
returnData.push.apply(returnData, responseData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +177,7 @@ export class QuickBase implements INodeType {
|
||||||
|
|
||||||
const versionNumber = this.getNodeParameter('versionNumber', i) as string;
|
const versionNumber = this.getNodeParameter('versionNumber', i) as string;
|
||||||
|
|
||||||
responseData = await quickbaseApiRequest.call(this,'DELETE', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`);
|
responseData = await quickbaseApiRequest.call(this, 'DELETE', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`);
|
||||||
|
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
}
|
}
|
||||||
|
@ -210,20 +211,20 @@ export class QuickBase implements INodeType {
|
||||||
|
|
||||||
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
|
const dataPropertyNameDownload = this.getNodeParameter('binaryPropertyName', i) as string;
|
||||||
|
|
||||||
responseData = await quickbaseApiRequest.call(this,'GET', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`, {}, {}, { json: false, resolveWithFullResponse: true });
|
responseData = await quickbaseApiRequest.call(this, 'GET', `/files/${tableId}/${recordId}/${fieldId}/${versionNumber}`, {}, {}, { json: false, resolveWithFullResponse: true });
|
||||||
|
|
||||||
//content-disposition': 'attachment; filename="dog-puppy-on-garden-royalty-free-image-1586966191.jpg"',
|
//content-disposition': 'attachment; filename="dog-puppy-on-garden-royalty-free-image-1586966191.jpg"',
|
||||||
const contentDisposition = responseData.headers['content-disposition'];
|
const contentDisposition = responseData.headers['content-disposition'];
|
||||||
|
|
||||||
const data = Buffer.from(responseData.body as string, 'base64');
|
const data = Buffer.from(responseData.body as string, 'base64');
|
||||||
|
|
||||||
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, contentDisposition.split('=')[1]);
|
items[i].binary![dataPropertyNameDownload] = await this.helpers.prepareBinaryData(data as unknown as Buffer, contentDisposition.split('=')[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prepareOutputData(items);
|
return this.prepareOutputData(items);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource === 'record') {
|
if (resource === 'record') {
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
const tableId = this.getNodeParameter('tableId', 0) as string;
|
const tableId = this.getNodeParameter('tableId', 0) as string;
|
||||||
|
@ -248,7 +249,7 @@ export class QuickBase implements INodeType {
|
||||||
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
|
record[fieldsLabelKey[key].toString()] = { value: items[i].json[key] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.push(record);
|
data.push(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +270,7 @@ export class QuickBase implements INodeType {
|
||||||
if (simple === true) {
|
if (simple === true) {
|
||||||
const { data: records } = responseData;
|
const { data: records } = responseData;
|
||||||
responseData = [];
|
responseData = [];
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const data: IDataObject = {};
|
const data: IDataObject = {};
|
||||||
for (const [key, value] of Object.entries(record)) {
|
for (const [key, value] of Object.entries(record)) {
|
||||||
|
@ -285,7 +286,7 @@ export class QuickBase implements INodeType {
|
||||||
returnData.push(responseData);
|
returnData.push(responseData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (operation === 'delete') {
|
if (operation === 'delete') {
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
const tableId = this.getNodeParameter('tableId', i) as string;
|
const tableId = this.getNodeParameter('tableId', i) as string;
|
||||||
|
@ -329,14 +330,14 @@ export class QuickBase implements INodeType {
|
||||||
// body.groupBy = group;
|
// body.groupBy = group;
|
||||||
// delete body.groupByUi;
|
// delete body.groupByUi;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', '/records/query', body, qs);
|
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', '/records/query', body, qs);
|
||||||
} else {
|
} else {
|
||||||
body.options = { top: this.getNodeParameter('limit', i) as number };
|
body.options = { top: this.getNodeParameter('limit', i) as number };
|
||||||
|
|
||||||
responseData = await quickbaseApiRequest.call(this, 'POST', '/records/query', body, qs);
|
responseData = await quickbaseApiRequest.call(this, 'POST', '/records/query', body, qs);
|
||||||
|
|
||||||
const { data: records, fields } = responseData;
|
const { data: records, fields } = responseData;
|
||||||
responseData = [];
|
responseData = [];
|
||||||
|
|
||||||
|
@ -345,7 +346,7 @@ export class QuickBase implements INodeType {
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
fieldsIdKey[field.id] = field.label;
|
fieldsIdKey[field.id] = field.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const data: IDataObject = {};
|
const data: IDataObject = {};
|
||||||
for (const [key, value] of Object.entries(record)) {
|
for (const [key, value] of Object.entries(record)) {
|
||||||
|
@ -389,7 +390,7 @@ export class QuickBase implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
record[fieldsLabelKey['Record ID#']] = { value: items[i].json[updateKey] };
|
record[fieldsLabelKey['Record ID#']] = { value: items[i].json[updateKey] };
|
||||||
|
|
||||||
data.push(record);
|
data.push(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,7 +411,7 @@ export class QuickBase implements INodeType {
|
||||||
if (simple === true) {
|
if (simple === true) {
|
||||||
const { data: records } = responseData;
|
const { data: records } = responseData;
|
||||||
responseData = [];
|
responseData = [];
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const data: IDataObject = {};
|
const data: IDataObject = {};
|
||||||
for (const [key, value] of Object.entries(record)) {
|
for (const [key, value] of Object.entries(record)) {
|
||||||
|
@ -460,7 +461,7 @@ export class QuickBase implements INodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
record[mergeFieldId] = { value: items[i].json[updateKey] };
|
record[mergeFieldId] = { value: items[i].json[updateKey] };
|
||||||
|
|
||||||
data.push(record);
|
data.push(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +483,7 @@ export class QuickBase implements INodeType {
|
||||||
if (simple === true) {
|
if (simple === true) {
|
||||||
const { data: records } = responseData;
|
const { data: records } = responseData;
|
||||||
responseData = [];
|
responseData = [];
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const data: IDataObject = {};
|
const data: IDataObject = {};
|
||||||
for (const [key, value] of Object.entries(record)) {
|
for (const [key, value] of Object.entries(record)) {
|
||||||
|
@ -516,7 +517,7 @@ export class QuickBase implements INodeType {
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
responseData = await quickbaseApiRequestAllItems.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
||||||
} else {
|
} else {
|
||||||
qs.top = this.getNodeParameter('limit', i) as number;
|
qs.top = this.getNodeParameter('limit', i) as number;
|
||||||
|
|
||||||
responseData = await quickbaseApiRequest.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
responseData = await quickbaseApiRequest.call(this, 'POST', `/reports/${reportId}/run`, {}, qs);
|
||||||
|
|
||||||
|
@ -528,7 +529,7 @@ export class QuickBase implements INodeType {
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
fieldsIdKey[field.id] = field.label;
|
fieldsIdKey[field.id] = field.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const data: IDataObject = {};
|
const data: IDataObject = {};
|
||||||
for (const [key, value] of Object.entries(record)) {
|
for (const [key, value] of Object.entries(record)) {
|
||||||
|
|
|
@ -83,6 +83,7 @@ export const recordFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
|
required: true,
|
||||||
placeholder: 'id,name,description',
|
placeholder: 'id,name,description',
|
||||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||||
},
|
},
|
||||||
|
@ -363,7 +364,7 @@ export const recordFields = [
|
||||||
name: 'where',
|
name: 'where',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'The filter, using the <a href="https://help.quickbase.com/api-guide/componentsquery.html" target="_blank">Quick Base query language</a>, which determines the records to return.',
|
description: 'The filter, using the <a href="https://help.quickbase.com/api-guide/componentsquery.html" target="_blank">Quick Base query language</a>, which determines the records to return.',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -403,6 +404,7 @@ export const recordFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
|
required: true,
|
||||||
placeholder: 'id,name,description',
|
placeholder: 'id,name,description',
|
||||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||||
},
|
},
|
||||||
|
@ -520,6 +522,7 @@ export const recordFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
default: '',
|
default: '',
|
||||||
|
required: true,
|
||||||
placeholder: 'id,name,description',
|
placeholder: 'id,name,description',
|
||||||
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
description: 'Comma separated list of the properties which should used as columns for the new rows.',
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,7 @@ export const reportFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The table identifier',
|
description: 'The table identifier.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Report ID',
|
displayName: 'Report ID',
|
||||||
|
@ -69,7 +69,7 @@ export const reportFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The identifier of the report, unique to the table',
|
description: 'The identifier of the report, unique to the table.',
|
||||||
},
|
},
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
/* report:run */
|
/* report:run */
|
||||||
|
@ -90,7 +90,7 @@ export const reportFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The table identifier',
|
description: 'The table identifier.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Report ID',
|
displayName: 'Report ID',
|
||||||
|
@ -108,7 +108,7 @@ export const reportFields = [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
description: 'The identifier of the report, unique to the table',
|
description: 'The identifier of the report, unique to the table.',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Return All',
|
displayName: 'Return All',
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in a new issue