mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
add process response group
This commit is contained in:
parent
b4406c48a8
commit
c57f838d51
|
@ -116,6 +116,25 @@ export async function processAttributes(
|
||||||
return requestOptions;
|
return requestOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper function to process Group Response */
|
||||||
|
export async function processGroupsResponse(
|
||||||
|
this: IExecuteSingleFunctions,
|
||||||
|
items: INodeExecutionData[],
|
||||||
|
response: IN8nHttpFullResponse,
|
||||||
|
): Promise<INodeExecutionData[]> {
|
||||||
|
const responseBody = response.body as { Groups: IDataObject[] };
|
||||||
|
|
||||||
|
if (!responseBody || !Array.isArray(responseBody.Groups)) {
|
||||||
|
throw new ApplicationError('Unexpected response format: No groups found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const executionData: INodeExecutionData[] = responseBody.Groups.map((group) => ({
|
||||||
|
json: group,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return executionData;
|
||||||
|
}
|
||||||
|
|
||||||
/* Helper function to handle pagination */
|
/* Helper function to handle pagination */
|
||||||
const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API
|
const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API
|
||||||
// ToDo: Test if pagination works
|
// ToDo: Test if pagination works
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow';
|
import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow';
|
||||||
import { NodeOperationError } from 'n8n-workflow';
|
import { NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import { handleErrorPostReceive } from '../GenericFunctions';
|
import { handleErrorPostReceive, processGroupsResponse } from '../GenericFunctions';
|
||||||
|
|
||||||
export const groupOperations: INodeProperties[] = [
|
export const groupOperations: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
|
@ -100,22 +100,7 @@ export const groupOperations: INodeProperties[] = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
postReceive: [
|
postReceive: [handleErrorPostReceive, processGroupsResponse],
|
||||||
handleErrorPostReceive,
|
|
||||||
{
|
|
||||||
type: 'set',
|
|
||||||
properties: {
|
|
||||||
value: '={{ $response.body.Groups }}',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'set',
|
|
||||||
properties: {
|
|
||||||
value:
|
|
||||||
'={{ $response.body.Groups.length > 10 && $parameter.simplified ? $response.body.Groups.map(group => ({ CreatedDate: group.CreatedDate, Description: group.Description, GroupName: group.GroupName, LastModifiedDate: group.LastModifiedDate })) : $response.body.Groups }}', // Simplify if more than 10 fields
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
action: 'Get many groups',
|
action: 'Get many groups',
|
||||||
|
|
Loading…
Reference in a new issue