mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix "Make an API call"
This commit is contained in:
parent
03594050f1
commit
9765219002
|
@ -1,25 +1,6 @@
|
||||||
import type { BaseProperties } from '../../Interfaces';
|
import type { BaseProperties } from '../../Interfaces';
|
||||||
|
|
||||||
export const baseApiCallDescription: BaseProperties = [
|
export const baseApiCallDescription: BaseProperties = [
|
||||||
{
|
|
||||||
displayName: 'Table Name',
|
|
||||||
name: 'tableName',
|
|
||||||
type: 'options',
|
|
||||||
placeholder: 'Select a table',
|
|
||||||
required: true,
|
|
||||||
typeOptions: {
|
|
||||||
loadOptionsMethod: 'getTableNames',
|
|
||||||
},
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: ['base'],
|
|
||||||
operation: ['apiCall'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
default: '',
|
|
||||||
description:
|
|
||||||
'The name of SeaTable table to access. Choose from the list, or specify a name using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'HTTP Method',
|
displayName: 'HTTP Method',
|
||||||
name: 'apiMethod',
|
name: 'apiMethod',
|
||||||
|
@ -34,8 +15,8 @@ export const baseApiCallDescription: BaseProperties = [
|
||||||
value: 'GET',
|
value: 'GET',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'POST',
|
name: 'PUT',
|
||||||
value: 'POST',
|
value: 'PUT',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'DELETE',
|
name: 'DELETE',
|
||||||
|
@ -133,4 +114,20 @@ export const baseApiCallDescription: BaseProperties = [
|
||||||
description:
|
description:
|
||||||
'Only valid JSON is accepted. n8n will pass anything you enter as raw input. For example, {"foo", "bar"} is perfectly valid. Of cause you can use variables from n8n inside your JSON.',
|
'Only valid JSON is accepted. n8n will pass anything you enter as raw input. For example, {"foo", "bar"} is perfectly valid. Of cause you can use variables from n8n inside your JSON.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Response object parameter name',
|
||||||
|
name: 'responseObjectName',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'Leave it empty or use a value like "rows", "metadata", "views" etc.',
|
||||||
|
required: false,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: ['base'],
|
||||||
|
operation: ['apiCall'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description:
|
||||||
|
'When using the SeaTable API, you can specify a parameter to retrieve either the entire array of objects or a specific object within it. This allows you to choose whether to fetch the complete output or only the object related to the provided parameter.',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,15 +1,40 @@
|
||||||
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
import type { IExecuteFunctions, IDataObject, INodeExecutionData } from 'n8n-workflow';
|
||||||
import { seaTableApiRequest } from '../../../GenericFunctions';
|
import { seaTableApiRequest } from '../../../GenericFunctions';
|
||||||
|
import { APITypes } from '../../../types';
|
||||||
|
|
||||||
export async function apiCall(
|
export async function apiCall(
|
||||||
this: IExecuteFunctions,
|
this: IExecuteFunctions,
|
||||||
index: number,
|
index: number,
|
||||||
): Promise<INodeExecutionData[]> {
|
): Promise<INodeExecutionData[]> {
|
||||||
|
const apiMethod = this.getNodeParameter('apiMethod', index) as APITypes;
|
||||||
|
const apiEndpoint = this.getNodeParameter('apiEndpoint', index) as APITypes;
|
||||||
|
const responseObjectName = this.getNodeParameter('responseObjectName', index) as string;
|
||||||
|
|
||||||
|
// body params
|
||||||
|
const apiBody = this.getNodeParameter('apiBody', index) as any;
|
||||||
|
|
||||||
|
// query params
|
||||||
|
const apiParams: IDataObject = {};
|
||||||
|
const params = this.getNodeParameter('apiParams.apiParamsValues', index, []) as any;
|
||||||
|
for (const param of params) {
|
||||||
|
apiParams[`${param.key}`] = param.value;
|
||||||
|
}
|
||||||
|
console.log(apiParams);
|
||||||
|
|
||||||
const responseData = await seaTableApiRequest.call(
|
const responseData = await seaTableApiRequest.call(
|
||||||
this,
|
this,
|
||||||
{},
|
{},
|
||||||
'GET',
|
apiMethod,
|
||||||
'/dtable-server/api/v1/dtables/{{dtable_uuid}}/metadata/',
|
apiEndpoint,
|
||||||
|
apiBody,
|
||||||
|
apiParams,
|
||||||
);
|
);
|
||||||
return this.helpers.returnJsonArray(responseData.metadata as IDataObject[]);
|
console.log(responseData);
|
||||||
|
|
||||||
|
// output
|
||||||
|
if (responseObjectName) {
|
||||||
|
return this.helpers.returnJsonArray(responseData[responseObjectName] as IDataObject[]);
|
||||||
|
} else {
|
||||||
|
return this.helpers.returnJsonArray(responseData as IDataObject[]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,3 +95,5 @@ export type TColumnsUiValues = Array<{
|
||||||
columnName: string;
|
columnName: string;
|
||||||
columnValue: string;
|
columnValue: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
export type APITypes = 'GET' | 'POST' | 'DELETE' | 'PUT';
|
||||||
|
|
Loading…
Reference in a new issue