mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 20:24:05 -08:00
⚡ Move "organizationId" in credentials and fix error messages
This commit is contained in:
parent
9250163c8c
commit
b36efd4c9d
|
@ -8,6 +8,12 @@ export class FlowApi implements ICredentialType {
|
|||
name = 'flowApi';
|
||||
displayName = 'Flow API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'number' as NodePropertyTypes,
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token',
|
||||
name: 'accessToken',
|
||||
|
|
|
@ -64,6 +64,12 @@ export class Flow implements INodeType {
|
|||
};
|
||||
|
||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||
const credentials = this.getCredentials('flowApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const items = this.getInputData();
|
||||
const returnData: IDataObject[] = [];
|
||||
const length = items.length as unknown as number;
|
||||
|
@ -76,12 +82,11 @@ export class Flow implements INodeType {
|
|||
if (resource === 'task') {
|
||||
//https://developer.getflow.com/api/#tasks_create-task
|
||||
if (operation === 'create') {
|
||||
const organizationId = this.getNodeParameter('organizationId', i) as string;
|
||||
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const body: ITask = {
|
||||
organization_id: parseInt(organizationId, 10),
|
||||
organization_id: credentials.organizationId as number,
|
||||
};
|
||||
const task: TaskInfo = {
|
||||
name,
|
||||
|
@ -134,17 +139,16 @@ export class Flow implements INodeType {
|
|||
responseData = await flowApiRequest.call(this, 'POST', '/tasks', body);
|
||||
responseData = responseData.task;
|
||||
} catch (err) {
|
||||
throw new Error(`Flow Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`Flow Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
//https://developer.getflow.com/api/#tasks_update-a-task
|
||||
if (operation === 'update') {
|
||||
const organizationId = this.getNodeParameter('organizationId', i) as string;
|
||||
const workspaceId = this.getNodeParameter('workspaceId', i) as string;
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const body: ITask = {
|
||||
organization_id: parseInt(organizationId, 10),
|
||||
organization_id: credentials.organizationId as number,
|
||||
};
|
||||
const task: TaskInfo = {
|
||||
workspace_id: parseInt(workspaceId, 10),
|
||||
|
@ -203,30 +207,28 @@ export class Flow implements INodeType {
|
|||
responseData = await flowApiRequest.call(this, 'PUT', `/tasks/${taskId}`, body);
|
||||
responseData = responseData.task;
|
||||
} catch (err) {
|
||||
throw new Error(`Flow Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`Flow Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
//https://developer.getflow.com/api/#tasks_get-task
|
||||
if (operation === 'get') {
|
||||
const organizationId = this.getNodeParameter('organizationId', i) as string;
|
||||
const taskId = this.getNodeParameter('taskId', i) as string;
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
qs.organization_id = organizationId;
|
||||
qs.organization_id = credentials.organizationId as number;
|
||||
if (filters.include) {
|
||||
qs.include = (filters.include as string[]).join(',');
|
||||
}
|
||||
try {
|
||||
responseData = await flowApiRequest.call(this,'GET', `/tasks/${taskId}`, {}, qs);
|
||||
} catch (err) {
|
||||
throw new Error(`Flow Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`Flow Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
//https://developer.getflow.com/api/#tasks_get-tasks
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const organizationId = this.getNodeParameter('organizationId', i) as string;
|
||||
const filters = this.getNodeParameter('filters', i) as IDataObject;
|
||||
qs.organization_id = organizationId;
|
||||
qs.organization_id = credentials.organizationId as number;
|
||||
if (filters.include) {
|
||||
qs.include = (filters.include as string[]).join(',');
|
||||
}
|
||||
|
@ -263,7 +265,7 @@ export class Flow implements INodeType {
|
|||
responseData = responseData.tasks;
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(`Flow Error: ${JSON.stringify(err)}`);
|
||||
throw new Error(`Flow Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,14 +43,6 @@ export class FlowTrigger implements INodeType {
|
|||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: '',
|
||||
description: 'Organization',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
|
@ -116,6 +108,12 @@ export class FlowTrigger implements INodeType {
|
|||
webhookMethods = {
|
||||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const credentials = this.getCredentials('flowApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let webhooks;
|
||||
const qs: IDataObject = {};
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
|
@ -125,7 +123,7 @@ export class FlowTrigger implements INodeType {
|
|||
if (!(webhookData.webhookIds as [number]).length) {
|
||||
return false;
|
||||
}
|
||||
qs.organization_id = this.getNodeParameter('organizationId') as string;
|
||||
qs.organization_id = credentials.organizationId as number;
|
||||
const endpoint = `/integration_webhooks`;
|
||||
try {
|
||||
webhooks = await flowApiRequest.call(this, 'GET', endpoint, {}, qs);
|
||||
|
@ -144,10 +142,15 @@ export class FlowTrigger implements INodeType {
|
|||
return true;
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const credentials = this.getCredentials('flowApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let resourceIds, body, responseData;
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const organizationId = this.getNodeParameter('organizationId') as string;
|
||||
const resource = this.getNodeParameter('resource') as string;
|
||||
const endpoint = `/integration_webhooks`;
|
||||
if (resource === 'list') {
|
||||
|
@ -159,7 +162,7 @@ export class FlowTrigger implements INodeType {
|
|||
// @ts-ignore
|
||||
for (const resourceId of resourceIds ) {
|
||||
body = {
|
||||
organization_id: organizationId,
|
||||
organization_id: credentials.organizationId as number,
|
||||
integration_webhook: {
|
||||
name: 'n8n-trigger',
|
||||
url: webhookUrl,
|
||||
|
@ -183,9 +186,15 @@ export class FlowTrigger implements INodeType {
|
|||
return true;
|
||||
},
|
||||
async delete(this: IHookFunctions): Promise<boolean> {
|
||||
const credentials = this.getCredentials('flowApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const qs: IDataObject = {};
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
qs.organization_id = this.getNodeParameter('organizationId') as string;
|
||||
qs.organization_id = credentials.organizationId as number;
|
||||
// @ts-ignore
|
||||
if (webhookData.webhookIds.length > 0) {
|
||||
// @ts-ignore
|
||||
|
|
|
@ -25,17 +25,16 @@ export async function flowApiRequest(this: IHookFunctions | IExecuteFunctions |
|
|||
if (Object.keys(options.body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
||||
|
||||
if (errorMessage !== undefined) {
|
||||
throw errorMessage;
|
||||
let errorMessage = error.message;
|
||||
if (error.response.body) {
|
||||
errorMessage = error.response.body.message || error.response.body.Message || error.message;
|
||||
}
|
||||
throw error.response.body;
|
||||
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,23 +44,6 @@ export const taskFields = [
|
|||
/* -------------------------------------------------------------------------- */
|
||||
/* task:create */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'task',
|
||||
],
|
||||
operation: [
|
||||
'create'
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Select resources belonging to an organization.',
|
||||
},
|
||||
{
|
||||
displayName: 'Workspace ID',
|
||||
name: 'workspaceId',
|
||||
|
@ -246,23 +229,6 @@ export const taskFields = [
|
|||
/* -------------------------------------------------------------------------- */
|
||||
/* task:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'task',
|
||||
],
|
||||
operation: [
|
||||
'update'
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Select resources belonging to an organization.',
|
||||
},
|
||||
{
|
||||
displayName: 'Workspace ID',
|
||||
name: 'workspaceId',
|
||||
|
@ -449,23 +415,6 @@ export const taskFields = [
|
|||
/* -------------------------------------------------------------------------- */
|
||||
/* task:get */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'task',
|
||||
],
|
||||
operation: [
|
||||
'get'
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Select resources belonging to an organization.',
|
||||
},
|
||||
{
|
||||
displayName: 'Task ID',
|
||||
name: 'taskId',
|
||||
|
@ -529,23 +478,6 @@ export const taskFields = [
|
|||
/* -------------------------------------------------------------------------- */
|
||||
/* task:getAll */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Organization ID',
|
||||
name: 'organizationId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'task',
|
||||
],
|
||||
operation: [
|
||||
'getAll'
|
||||
]
|
||||
},
|
||||
},
|
||||
description: 'Select resources belonging to an organization.',
|
||||
},
|
||||
{
|
||||
displayName: 'Return All',
|
||||
name: 'returnAll',
|
||||
|
|
Loading…
Reference in a new issue