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.0 KB
Raw Blame
import { createAction, Property } from '@activepieces/pieces-framework';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { villageAuth, VILLAGE_API_BASE_URL } from '../../common/auth';

export const peopleRefresh = createAction({
  auth: villageAuth,
  name: 'people_refresh',
  classification: 'WRITE',
  displayName: 'Refresh People',
  description:
    'Refresh or import people data from LinkedIn URLs. In realtime mode, returns enriched person data immediately (or times out after 25 seconds and converts to async). In async mode, returns job IDs for later status checking.',
  audience: 'both',
  aiMetadata: {
    description:
      'Trigger a re-fetch or first-time import of people into your network from LinkedIn URLs; this kicks off backend processing, so treat it as a non-idempotent write rather than a plain read. Set realtime=true to wait up to ~25s for enriched data inline, or false to get job IDs to poll later. To read already-imported profiles without re-fetching, use Enrich Person instead.',
    idempotent: false,
  },
  props: {
    linkedin_urls: Property.Array({
      displayName: 'LinkedIn URLs',
      description: 'LinkedIn profile URLs to refresh. At least one is required.',
      required: true,
      defaultValue: [],
    }),
    realtime: Property.Checkbox({
      displayName: 'Realtime',
      description:
        'If true, waits synchronously for results (up to 25s). If false, returns job IDs for async processing.',
      required: true,
    }),
  },
  async run(context) {
    const { linkedin_urls, realtime } = context.propsValue;

    if (!Array.isArray(linkedin_urls) || linkedin_urls.length === 0) {
      throw new Error('At least one LinkedIn URL is required.');
    }

    const response = await httpClient.sendRequest({
      method: HttpMethod.POST,
      url: `${VILLAGE_API_BASE_URL}/v2/people/refresh`,
      headers: { Authorization: `Bearer ${context.auth.secret_text}` },
      body: {
        linkedin_urls: linkedin_urls.map(String),
        realtime,
      },
    });
    return response.body;
  },
});