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

4.1 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { HttpMethod } from '@activepieces/pieces-common';
import { wrikeAuth } from '../common/auth';
import { wrikeCommon } from '../common/client';

export const findFolder = createAction({
    name: 'find_folder',
    displayName: 'Find Folder / Project',
    description: 'Retrieve folder / project metadata by ID or name',
    audience: 'both',
    aiMetadata: { description: 'Look up Wrike folders or projects: pass a folder ID to fetch that exact one (other criteria are ignored), or omit it to search/filter by title, parent folders, authors, owners, or the projects-only flag. Use when an agent needs to resolve or read folder/project metadata before acting. Read-only and idempotent.', idempotent: true },
    auth: wrikeAuth,
    props: {
        folderId: Property.ShortText({
            displayName: 'Folder ID',
            description: 'The ID of the folder/project to retrieve. If provided, other search criteria will be ignored.',
            required: false,
        }),
        title: Property.ShortText({
            displayName: 'Title',
            description: 'Search for folders/projects by title (partial match)',
            required: false,
        }),
        parentIds: Property.Array({
            displayName: 'Parent IDs',
            description: 'Search for folders/projects within specific parent folders',
            required: false,
            properties: {
                folderId: Property.ShortText({
                    displayName: 'Folder ID',
                    required: true,
                }),
            },
        }),
        project: Property.Checkbox({
            displayName: 'Is Project',
            description: 'Filter to only return projects (folders marked as projects)',
            required: false,
        }),
        pageSize: Property.Number({
            displayName: 'Page Size',
            description: 'Maximum number of folders/projects to return (max 1000)',
            required: false,
            defaultValue: 100,
        }),
        authors: Property.Array({
            displayName: 'Author IDs',
            description: 'Filter by authors (users who created the folders)',
            required: false,
            properties: {
                userId: Property.ShortText({
                    displayName: 'User ID',
                    required: true,
                }),
            },
        }),
        owners: Property.Array({
            displayName: 'Owner IDs',
            description: 'Filter by owners (users who own the projects)',
            required: false,
            properties: {
                userId: Property.ShortText({
                    displayName: 'User ID',
                    required: true,
                }),
            },
        }),
    },
    async run(context) {
        const props = context.propsValue as any;
        const { folderId, title, parentIds, project, pageSize, authors, owners } = props;

        if (folderId) {
            const response = await wrikeCommon.apiCall({
                auth: context.auth,
                method: HttpMethod.GET,
                resourceUri: `/folders/${folderId}`,
            });
            return response.body;
        }

        const queryParams: Record<string, string> = {};

        if (title) queryParams['title'] = title;
        if (parentIds && parentIds.length > 0) {
            queryParams['parentIds'] = parentIds.map((parent: any) => parent.folderId).join(',');
        }
        if (project !== undefined) queryParams['project'] = project.toString();
        if (pageSize) queryParams['pageSize'] = pageSize.toString();
        if (authors && authors.length > 0) {
            queryParams['authors'] = authors.map((author: any) => author.userId).join(',');
        }
        if (owners && owners.length > 0) {
            queryParams['owners'] = owners.map((owner: any) => owner.userId).join(',');
        }

        const response = await wrikeCommon.apiCall({
            auth: context.auth,
            method: HttpMethod.GET,
            resourceUri: '/folders',
            queryParams,
        });

        return response.body;
    },
});