| name | activepieces-6-custom-piece-development |
| description | Sub-skill of activepieces: 6. Custom Piece Development. |
| version | 1.0.0 |
| category | operations |
| type | reference |
| scripts_exempt | true |
6. Custom Piece Development
6. Custom Piece Development
import { createPiece, PieceAuth } from '@activepieces/pieces-framework';
import { createCustomResource } from './lib/actions/create-resource';
import { getCustomResource } from './lib/actions/get-resource';
import { listCustomResources } from './lib/actions/list-resources';
import { resourceCreatedTrigger } from './lib/triggers/resource-created';
const authDescription = `
To get your API key:
1. Go to Settings > API Keys in your dashboard
2. Click "Create New Key"
3. Copy the generated key
`;
export const customApiAuth = PieceAuth.SecretText({
displayName: 'API Key',
required: true,
description: authDescription,
validate: async ({ auth }) => {
const response = await fetch('https://api.example.com/validate', {
headers: { Authorization: `Bearer ${auth}` }
});
if (!response.ok) {
return {
valid: false,
error: 'Invalid API key'
};
}
return { valid: true };
}
});
export const myCustomApi = createPiece({
displayName: 'My Custom API',
auth: customApiAuth,
minimumSupportedRelease: '0.20.0',
logoUrl: 'https://example.com/logo.png',
authors: ['your-name'],
description: 'Connect to My Custom API for resource management',
actions: [createCustomResource, getCustomResource, listCustomResources],
triggers: [resourceCreatedTrigger]
});
import { createAction, Property } from '@activepieces/pieces-framework';
import { customApiAuth } from '../../index';
export const createCustomResource = createAction({
name: 'create_resource',
displayName: 'Create Resource',
description: 'Create a new resource in My Custom API',
auth: customApiAuth,
props: {
name: Property.ShortText({
displayName: 'Resource Name',
required: true,
description: 'The name of the resource'
}),
type: Property.Dropdown({
displayName: 'Resource Type',
required: true,
refreshers: [],
options: async () => ({
options: [
{ label: 'Document', value: 'document' },
{ label: 'Image', value: 'image' },
{ label: 'Video', value: }
]
})
}),
: .({
: ,
: ,
:
}),
: .({
: ,
: ,
:
}),
: .({
: ,
: ,
:
})
},
() {
{ auth, propsValue } = context;
response = (, {
: ,
: {
: ,
:
},
: .({
: propsValue.,
: propsValue.,
: propsValue. || [],
: propsValue. || {},
: propsValue.
})
});
(!response.) {
error = response.();
();
}
result = response.();
{
: result.,
: result.,
: result.,
: result.,
: result.
};
}
});
import {
createTrigger,
TriggerStrategy,
Property
} from '@activepieces/pieces-framework';
import { customApiAuth } from '../../index';
export const resourceCreatedTrigger = createTrigger({
name: 'resource_created',
displayName: 'Resource Created',
description: 'Triggers when a new resource is created',
auth: customApiAuth,
props: {
resourceType: Property.Dropdown({
displayName: 'Resource Type',
required: false,
refreshers: [],
options: async () => ({
options: [
{ label: 'All Types', value: 'all' },
{ label: 'Document', value: 'document' },
{ label: 'Image', value: 'image' },
{ label: 'Video', value: 'video' }
]
})
})
},
type: TriggerStrategy.,
() {
{ auth, propsValue, webhookUrl, store } = context;
response = (, {
: ,
: {
: ,
:
},
: .({
: webhookUrl,
: [],
: propsValue. !==
? { : propsValue. }
:
})
});
webhook = response.();
store.(, webhook.);
},
() {
{ auth, store } = context;
* truncated — see parent skill full reference.*