Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.4 KB
Raw Blame
import { createAction, Property, PiecePropValueSchema } from '@activepieces/pieces-framework';
import { teamworkAuth } from '../common/auth';
import { teamworkRequest } from '../common/client';
import { HttpMethod } from '@activepieces/pieces-common';

export const addPeopleToProject = createAction({
	name: 'add_people_to_project',
	classification: 'WRITE',
	displayName: 'Add People to Project',
	description: 'Add existing users to a project.',
	audience: 'both',
	aiMetadata: { description: 'Adds existing Teamwork users to a project as members. Use to grant people access to a project after both the project and the users exist. Requires the target project and a list of user IDs. Idempotent — re-adding users already on the project leaves the membership unchanged.', idempotent: true },
	auth: teamworkAuth,
	props: {
		projectId: Property.Dropdown({
auth: teamworkAuth,
			
			displayName: 'Project',
			description: 'The project to add people to.',
			required: true,
			refreshers: [],
			options: async ({ auth }) => {
				if (!auth) {
					return {
						disabled: true,
						placeholder: 'Please authenticate first.',
						options: [],
					};
				}
				const res = await teamworkRequest(auth, {
					method: HttpMethod.GET,
					path: '/projects.json',
				});
				const options = res.data.projects.map((p: { id: string; name: string }) => ({
					label: p.name,
					value: p.id,
				}));
				return {
					disabled: false,
					options,
				};
			},
		}),
		userIdList: Property.MultiSelectDropdown({
auth: teamworkAuth,
			displayName: 'Users',
			description: 'The users to add to the project.',
			required: true,
			refreshers: [],
			options: async ({ auth }) => {
				if (!auth) {
					return {
						disabled: true,
						placeholder: 'Please authenticate first.',
						options: [],
					};
				}
				const res = await teamworkRequest(auth, {
					method: HttpMethod.GET,
					path: '/people.json',
				});
				const options = res.data.people.map((p: { id: string; 'first-name': string; 'last-name': string }) => ({
					label: `${p['first-name']} ${p['last-name']}`,
					value: p.id,
				}));
				return {
					disabled: false,
					options,
				};
			},
		}),
	},
	async run({ auth, propsValue }) {
		const body = {
			add: {
				userIdList: propsValue.userIdList.join(','),
			},
		};
		return await teamworkRequest(auth, {
			method: HttpMethod.POST,
			path: `/projects/${propsValue.projectId}/people.json`,
			body,
		});
	},
});