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

1.7 KB
Raw Blame
import { pipedriveAuth } from '../auth';
import { createAction, Property } from '@activepieces/pieces-framework';
import { pipedriveApiCall } from '../common';
import { HttpMethod } from '@activepieces/pieces-common';
import { findUserActionOutputSchema } from '../output-schemas';

export const findUserAction = createAction({
	auth: pipedriveAuth,
	name: 'find-user',
	outputSchema: findUserActionOutputSchema,
	classification: 'SEARCH',
	displayName: 'Find User',
	description: 'Finds a user by name or email.',
	audience: 'both',
	aiMetadata: { description: 'Search Pipedrive account users (team members, not CRM persons) by name or by email address. Pick this to resolve an owner or assignee to a user ID; choose the search-by field to match either a name or an email term. Read-only and may return multiple matches.', idempotent: true },
	props: {
		field: Property.StaticDropdown({
			displayName: 'Field to search by',
			required: true,
			options: {
				disabled: false,
				options: [
					{
						label: 'Name',
						value: 'name',
					},
					{
						label: 'Email',
						value: 'email',
					},
				],
			},
		}),
		fieldValue: Property.ShortText({
			displayName: 'Field Value',
			required: true,
		}),
	},
	async run(context) {
		const { field, fieldValue } = context.propsValue;

		const response = await pipedriveApiCall<{ success: boolean; data: Array<Record<string, any>> }>(
			{
				accessToken: context.auth.access_token,
				apiDomain: context.auth.data['api_domain'],
				method: HttpMethod.GET,
				resourceUri: '/v1/users/find',
				query: {
					term: fieldValue,
					search_by_email: field == 'email' ? 1 : 0,
				},
			},
		);

		return {
			found: response.data && response.data.length > 0, 
			data: response.data,
		};
	},
});