Add API Endpoint
Create endpoint for $ARGUMENTS.
Steps
Read the pattern: Open
packages/server/api/src/app/tables/table/table.controller.tsas reference.Create or update controller using
FastifyPluginAsyncZod:export const myController: FastifyPluginAsyncZod = async (fastify) => { fastify.post('/', CreateRequest, async (request) => { return myService(request.log).create({ projectId: request.projectId, request: request.body, }) }) }Define route config AFTER the controller (not inline):
const CreateRequest = { config: { security: securityAccess.project( [PrincipalType.USER, PrincipalType.ENGINE, PrincipalType.SERVICE], Permission.WRITE_MY_FEATURE, { type: ProjectResourceType.BODY }, ), }, schema: { tags: ['my-feature'], body: CreateMyFeatureRequest, // Zod schema from @activepieces/shared response: { [StatusCodes.CREATED]: MyFeature }, }, }Security access (pick one):
securityAccess.project(principals, permission, { type: ProjectResourceType.X })— project-scopedsecurityAccess.platformAdminOnly(principals)— admin onlysecurityAccess.publicPlatform(principals)— any platform membersecurityAccess.public()— no auth
Create module and register in
app.ts:export const myModule: FastifyPluginAsyncZod = async (app) => { app.addHook('preSerialization', entitiesMustBeOwnedByCurrentProject) await app.register(myController, { prefix: '/v1/my-features' }) }Add Permission if new: add to
Permissionenum in@activepieces/shared.Verify:
npm run lint-dev