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 { HttpMethod } from '@activepieces/pieces-common';
import { createAction, Property } from '@activepieces/pieces-framework';
import { bitlyApiCall } from '../common/client';
import { bitlyAuth } from '../common/auth';
import { bitlinkDropdown, groupGuid } from '../common/props';

export const archiveBitlinkAction = createAction({
  auth: bitlyAuth,
  name: 'archive_bitlink',
  classification: 'DESTRUCTIVE',
  displayName: 'Archive Bitlink',
  description: 'Archive a Bitlink to stop redirects.',
  audience: 'both',
  aiMetadata: { description: 'Archives an existing Bitlink so it stops redirecting, identified by its Bitlink ID (e.g. bit.ly/xyz123). Use to retire or disable a short link. Idempotent: re-archiving an already-archived link leaves it archived with no additional effect.', idempotent: true },
  props: {
    group_guid: groupGuid,
    bitlink: bitlinkDropdown,
  },
  async run(context) {
    const { bitlink } = context.propsValue;

    try {
      const body = {
        archived: true,
      };

      return await bitlyApiCall({
        method: HttpMethod.PATCH,
        auth: context.auth.props,
        resourceUri: `/bitlinks/${bitlink}`,
        body,
      });

    } catch (error: any) {
      const errorMessage = error.response?.data?.description || error.response?.data?.message || error.message;

      if (error.response?.status === 429) {
        throw new Error(
          'Rate limit exceeded. Please wait before trying again.'
        );
      }

      if (error.response?.status === 404) {
        throw new Error(
          `Bitlink not found: ${errorMessage}. Please verify the link (e.g., 'bit.ly/xyz123') is correct.`
        );
      }

      if (error.response?.status === 401 || error.response?.status === 403) {
        throw new Error(
          `Authentication failed or forbidden: ${errorMessage}. Please check your Access Token and permissions.`
        );
      }

      throw new Error(
        `Failed to archive Bitlink: ${errorMessage || 'Unknown error occurred'}`
      );
    }
  },
});