Let n8n create and update campaigns with scope sources

Replace the separate Add Source operation with multi-select source
fields on create and update. Create passes accessReviewSourceIds to
the existing GraphQL input; update gains the same omittable field and
backend source sync so workflows can configure sources in one step.

Load source options from the organization in the n8n UI, and keep
surfacing INVALID errors when start fails for missing sources.

Signed-off-by: Cursor Agent <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-07-20 15:37:36 +00:00
parent 2d93b1d793
commit ffaf637397
13 changed files with 335 additions and 107 deletions

View File

@@ -21,6 +21,7 @@
import type {
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IDataObject,
JsonObject,
IHttpRequestOptions,
@@ -35,8 +36,10 @@ type ApiRequestFn = (
variables?: IDataObject,
) => Promise<IDataObject>;
type ApiRequestContext = IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions;
async function proboGraphqlRequest(
this: IExecuteFunctions | IHookFunctions,
this: ApiRequestContext,
apiPath: string,
query: string,
variables: IDataObject = {},
@@ -82,7 +85,7 @@ async function proboGraphqlRequest(
}
export async function proboApiRequest(
this: IExecuteFunctions | IHookFunctions,
this: ApiRequestContext,
query: string,
variables: IDataObject = {},
): Promise<IDataObject> {
@@ -160,7 +163,7 @@ export async function proboApiRequestAllItems(
): Promise<IDataObject[]> {
return proboGraphqlRequestAllItems.call(
this,
proboApiRequest,
proboApiRequest as ApiRequestFn,
query,
variables,
getConnection,
@@ -179,7 +182,7 @@ export async function proboConnectApiRequestAllItems(
): Promise<IDataObject[]> {
return proboGraphqlRequestAllItems.call(
this,
proboConnectApiRequest,
proboConnectApiRequest as ApiRequestFn,
query,
variables,
getConnection,

View File

@@ -31,6 +31,7 @@ import {
getAllResourceFields,
getExecuteFunction,
} from './actions';
import { getAccessReviewSources } from './actions/accessReview/loadAccessReviewSourceOptions';
export class Probo implements INodeType {
description: INodeTypeDescription = {
@@ -273,6 +274,9 @@ export class Probo implements INodeType {
}
methods = {
loadOptions: {
getAccessReviewSources,
},
listSearch: {},
};
}

View File

@@ -1,87 +0,0 @@
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { proboApiRequest } from '../../GenericFunctions';
export const description: INodeProperties[] = [
{
displayName: 'Access Review Campaign ID',
name: 'accessReviewCampaignId',
type: 'string',
displayOptions: {
show: {
resource: ['accessReview'],
operation: ['addSource'],
},
},
default: '',
description: 'The ID of the access review campaign',
required: true,
},
{
displayName: 'Access Review Source ID',
name: 'accessReviewSourceId',
type: 'string',
displayOptions: {
show: {
resource: ['accessReview'],
operation: ['addSource'],
},
},
default: '',
description: 'The ID of the access review source to add to the campaign',
required: true,
},
];
export async function execute(
this: IExecuteFunctions,
itemIndex: number,
): Promise<INodeExecutionData> {
const accessReviewCampaignId = this.getNodeParameter('accessReviewCampaignId', itemIndex) as string;
const accessReviewSourceId = this.getNodeParameter('accessReviewSourceId', itemIndex) as string;
const query = `
mutation AddAccessReviewCampaignSource($input: AddAccessReviewCampaignSourceInput!) {
addAccessReviewCampaignSource(input: $input) {
accessReviewCampaign {
id
name
description
status
startedAt
completedAt
createdAt
updatedAt
}
}
}
`;
const responseData = await proboApiRequest.call(this, query, {
input: { accessReviewCampaignId, accessReviewSourceId },
});
return {
json: responseData,
pairedItem: { item: itemIndex },
};
}

View File

@@ -20,6 +20,7 @@
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { proboApiRequest } from '../../GenericFunctions';
import { accessReviewSourceIdsField } from './sources.fields';
export const description: INodeProperties[] = [
{
@@ -63,6 +64,7 @@ export const description: INodeProperties[] = [
default: '',
description: 'The description of the access review campaign',
},
accessReviewSourceIdsField,
];
export async function execute(
@@ -72,6 +74,7 @@ export async function execute(
const organizationId = this.getNodeParameter('organizationId', itemIndex) as string;
const name = this.getNodeParameter('name', itemIndex) as string;
const description = this.getNodeParameter('description', itemIndex, '') as string;
const accessReviewSourceIds = this.getNodeParameter('accessReviewSourceIds', itemIndex, []) as string[];
const query = `
mutation CreateAccessReviewCampaign($input: CreateAccessReviewCampaignInput!) {
@@ -97,6 +100,7 @@ export async function execute(
organizationId,
name,
...(description && { description }),
...(accessReviewSourceIds.length > 0 && { accessReviewSourceIds }),
},
};

View File

@@ -19,7 +19,6 @@
// SOFTWARE.
import type { INodeProperties } from 'n8n-workflow';
import * as addSourceOp from './addSource.operation';
import * as createOp from './create.operation';
import * as deleteOp from './delete.operation';
import * as getOp from './get.operation';
@@ -41,12 +40,6 @@ export const description: INodeProperties[] = [
},
},
options: [
{
name: 'Add Source',
value: 'addSource',
description: 'Add a scope source to an access review campaign',
action: 'Add a scope source to an access review campaign',
},
{
name: 'Cancel',
value: 'cancel',
@@ -98,7 +91,6 @@ export const description: INodeProperties[] = [
],
default: 'create',
},
...addSourceOp.description,
...createOp.description,
...deleteOp.description,
...getOp.description,
@@ -110,7 +102,6 @@ export const description: INodeProperties[] = [
];
export {
addSourceOp as addSource,
createOp as create,
deleteOp as delete,
getOp as get,

View File

@@ -0,0 +1,104 @@
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import type { IDataObject, ILoadOptionsFunctions, INodePropertyOptions } from 'n8n-workflow';
import { proboApiRequest } from '../../GenericFunctions';
const organizationSourcesQuery = `
query AccessReviewSources($organizationId: ID!) {
organization: node(id: $organizationId) {
... on Organization {
accessReviewSources(first: 500) {
edges {
node {
id
name
}
}
}
}
}
}
`;
const campaignOrganizationQuery = `
query AccessReviewCampaignOrganization($accessReviewCampaignId: ID!) {
campaign: node(id: $accessReviewCampaignId) {
... on AccessReviewCampaign {
organization {
id
}
}
}
}
`;
function mapSources(responseData: IDataObject): INodePropertyOptions[] {
const data = responseData.data as IDataObject | undefined;
const organization = data?.organization as IDataObject | undefined;
const accessReviewSources = organization?.accessReviewSources as IDataObject | undefined;
const edges = accessReviewSources?.edges as Array<{ node: IDataObject }> | undefined;
return (edges ?? [])
.map((edge) => edge.node)
.filter((node): node is IDataObject => node !== undefined && typeof node.id === 'string')
.map((node) => ({
name: String(node.name ?? node.id),
value: String(node.id),
}));
}
async function resolveOrganizationId(
this: ILoadOptionsFunctions,
): Promise<string | undefined> {
const organizationId = this.getCurrentNodeParameter('organizationId') as string | undefined;
if (organizationId) {
return organizationId;
}
const accessReviewCampaignId = this.getCurrentNodeParameter('accessReviewCampaignId') as string | undefined;
if (!accessReviewCampaignId) {
return undefined;
}
const responseData = await proboApiRequest.call(this, campaignOrganizationQuery, {
accessReviewCampaignId,
});
const data = responseData.data as IDataObject | undefined;
const campaign = data?.campaign as IDataObject | undefined;
const organization = campaign?.organization as IDataObject | undefined;
return typeof organization?.id === 'string' ? organization.id : undefined;
}
export async function getAccessReviewSources(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const organizationId = await resolveOrganizationId.call(this);
if (!organizationId) {
return [];
}
const responseData = await proboApiRequest.call(this, organizationSourcesQuery, {
organizationId,
});
return mapSources(responseData);
}

View File

@@ -0,0 +1,51 @@
// Copyright (c) 2025-2026 Probo Inc <hello@probo.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import type { INodeProperties } from 'n8n-workflow';
export const accessReviewSourceIdsField: INodeProperties = {
displayName: 'Source Names or IDs',
name: 'accessReviewSourceIds',
type: 'multiOptions',
displayOptions: {
show: {
resource: ['accessReview'],
operation: ['create'],
},
},
typeOptions: {
loadOptionsMethod: 'getAccessReviewSources',
loadOptionsDependsOn: ['organizationId'],
},
default: [],
description: 'Scope sources to include in the campaign. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
};
export const accessReviewSourceIdsUpdateField: INodeProperties = {
displayName: 'Source Names or IDs',
name: 'accessReviewSourceIds',
type: 'multiOptions',
typeOptions: {
loadOptionsMethod: 'getAccessReviewSources',
loadOptionsDependsOn: ['accessReviewCampaignId'],
},
default: [],
description: 'Replace the campaign scope sources with this selection. Choose from the list, or specify IDs using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
};

View File

@@ -20,6 +20,7 @@
import type { INodeProperties, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { proboApiRequest } from '../../GenericFunctions';
import { accessReviewSourceIdsUpdateField } from './sources.fields';
export const description: INodeProperties[] = [
{
@@ -62,6 +63,20 @@ export const description: INodeProperties[] = [
default: '',
description: 'The description of the access review campaign',
},
{
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: ['accessReview'],
operation: ['update'],
},
},
options: [accessReviewSourceIdsUpdateField],
},
];
export async function execute(
@@ -71,6 +86,9 @@ export async function execute(
const accessReviewCampaignId = this.getNodeParameter('accessReviewCampaignId', itemIndex) as string;
const name = this.getNodeParameter('name', itemIndex, '') as string;
const description = this.getNodeParameter('description', itemIndex, '') as string;
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {}) as {
accessReviewSourceIds?: string[];
};
const query = `
mutation UpdateAccessReviewCampaign($input: UpdateAccessReviewCampaignInput!) {
@@ -89,9 +107,12 @@ export async function execute(
}
`;
const input: Record<string, string> = { accessReviewCampaignId };
const input: Record<string, string | string[]> = { accessReviewCampaignId };
if (name) input.name = name;
if (description) input.description = description;
if (additionalFields.accessReviewSourceIds !== undefined) {
input.accessReviewSourceIds = additionalFields.accessReviewSourceIds;
}
const responseData = await proboApiRequest.call(this, query, { input });