add process response group

This commit is contained in:
Stamsy 2024-11-27 12:12:51 +02:00
parent b4406c48a8
commit c57f838d51
2 changed files with 21 additions and 17 deletions

View file

@ -116,6 +116,25 @@ export async function processAttributes(
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 */
const possibleRootProperties = ['Users']; // Root properties that can be returned by the list operations of the API
// ToDo: Test if pagination works

View file

@ -1,7 +1,7 @@
import type { IExecuteSingleFunctions, IHttpRequestOptions, INodeProperties } from 'n8n-workflow';
import { NodeOperationError } from 'n8n-workflow';
import { handleErrorPostReceive } from '../GenericFunctions';
import { handleErrorPostReceive, processGroupsResponse } from '../GenericFunctions';
export const groupOperations: INodeProperties[] = [
{
@ -100,22 +100,7 @@ export const groupOperations: INodeProperties[] = [
},
},
output: {
postReceive: [
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
},
},
],
postReceive: [handleErrorPostReceive, processGroupsResponse],
},
},
action: 'Get many groups',