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

import { captainDataAuth } from '../..';
import { CAPTAIN_DATA_BASE_URL, CaptainDataAuthType } from '../..';
import { workflowProp } from '../common';

export const getJobResults = createAction({
  // auth: check https://www.activepieces.com/docs/developers/piece-reference/authentication,
  name: 'getJobResults',
  classification: 'READ',
  displayName: 'Get job results',
  description: 'Get all results for a specific job',
  audience: 'both',
  aiMetadata: {
    description:
      'Retrieves all output records produced by a specific Captain Data job (a single past run of a workflow), identified by its workflow UID and job UID. Use this to read the data a launched workflow has gathered. Read-only and idempotent; results are not paginated.',
    idempotent: true,
  },
  auth: captainDataAuth,
  props: {
    workflow: workflowProp,
    job: Property.Dropdown({
      auth: captainDataAuth,
      displayName: 'Job',
      required: true,
      refreshers: ['workflow'],
      options: async ({ auth, workflow }) => {
        if (!auth || !workflow) {
          return {
            disabled: true,
            options: [],
          };
        }
        const response = await httpClient.sendRequest({
          url: `${CAPTAIN_DATA_BASE_URL}/workflows/${workflow}/jobs`,
          method: HttpMethod.GET,
          headers: {
            Authorization: `x-api-key ${auth.props.apiKey}`,
            'x-project-id': auth.props.projectId,
          },
        });
        return {
          disabled: false,
          options: response.body.map(
            (job: {
              uid: string;
              name: string;
              workflow_name: string;
              status: string;
              start_time: string;
            }) => {
              return {
                value: job.uid,
                label: job.start_time,
              };
            }
          ),
        };
      },
    }),
  },
  async run({ auth, propsValue }) {
    // We don't do pagination because Captain Data's API doc does provide details nor even examples :shrug:
    const response = await httpClient.sendRequest({
      url: `${CAPTAIN_DATA_BASE_URL}/jobs/${propsValue.job}/results`,
      method: HttpMethod.GET,
      headers: {
        Authorization: `x-api-key ${auth.props.apiKey}`,
        'x-project-id': auth.props.projectId,
      },
    });
    return response.body;
  },
});