development.mdxβ’5.68 kB
---
title: "Development"
description: ""
icon: "wrench"
---
## Prerequisites
<Steps>
<Step title="Start the devcontainer">
Follow the documentation [here](/developers/development-setup/dev-container) to do so.
</Step>
<Step title="Set Your Environment Variables">
Update your packages/server-api/.env file to include:
```bash
## these variables are set to align with the .devcontainer/docker-compose.yml file
AP_DB_TYPE=POSTGRES
AP_DEV_PIECES="your_piece_name"
AP_ENVIRONMENT="dev"
AP_EDITION=ee
AP_EXECUTION_MODE=SANDBOXED
AP_FRONTEND_URL="http://localhost:4200"
AP_WEBHOOK_URL="http://localhost:3000"
AP_PIECES_SOURCE='FILE'
AP_PIECES_SYNC_MODE='NONE'
AP_LOG_LEVEL=debug
AP_LOG_PRETTY=true
AP_QUEUE_MODE=REDIS
AP_REDIS_HOST="redis"
AP_REDIS_PORT="6379"
AP_TRIGGER_DEFAULT_POLL_INTERVAL=1
AP_CACHE_PATH=/workspace/cache
AP_POSTGRES_DATABASE=activepieces
AP_POSTGRES_HOST=db
AP_POSTGRES_PORT=5432
AP_POSTGRES_USERNAME=postgres
AP_POSTGRES_PASSWORD=A79Vm5D4p2VQHOp2gd5
```
</Step>
<Step title="Activate Your License Key">
After signing in, activate the license key by going to **Platform Admin -> Setup -> License Keys**

</Step>
<Step title="Create Your Piece">
Follow the instructions [here](/developers/building-pieces/overview) to create your piece, after that come back here to customize the piece logic to use predefined connections.
</Step>
</Steps>
## Implementation
<Steps>
<Step title="Set Project External ID">
Go to your **Project Settings** and set the external Id to something specific like `xyz`:

</Step>
<Step title="Create Global Connection">
<Tip>We recommend creating global connections because only platform admins can delete or edit them, so your user can never delete the connection. </Tip>
Create a global connection by going to **Platform Admin -> Setup -> Global Connections** and set the external ID to something like `gelato_xyz`:

<Tip>You can only edit the external ID when creating the connection, and to view the external id of the connection, just hover its name in the table.</Tip>
</Step>
<Step title="Don't Ask for Authentication in Your Actions/Triggers">
After you have created your [piece definition](../developers/building-pieces/piece-definition) and added [its authentication](../developers/building-pieces/piece-authentication).
Once you are [creating an action](../developers/building-pieces/create-action) or a [trigger](..developers/building-pieces/create-trigger), you can set the param `requireAuth` to be false in the `createAction` or `createTrigger` methods.
</Step>
<Step title="Fetch Connections to Use in Actions/Triggers">
Let's suppose the predefined connection externalId you want to store is **gelato_projectExternalId**, now in **run/test** method of your action or trigger, or the **onEnable/onDisable/onRenew** methods in your trigger, you can fetch the connection like this:
```ts
import { ConnectionsManager, Property, TriggerStrategy } from "@activepieces/pieces-framework";
import { createTrigger } from "@activepieces/pieces-framework";
import { AppConnectionType, AppConnectionValue, isNil } from "@activepieces/shared";
const fetchConnection = async<T extends AppConnectionType> (connections: ConnectionsManager, projectExternalId: string | undefined): Promise<AppConnectionValue<T>> => {
if (isNil(projectExternalId)) {
throw new Error('Project external ID is required');
}
const connection = await connections.get(`gelato_${projectExternalId}`);
if (isNil(connection)) {
throw new Error(`Connection not found for project ${projectExternalId}`);
}
return connection as AppConnectionValue<T>;
}
export const newFlavorCreated = createTrigger({
requireAuth:false,
name: 'newFlavorCreated',
displayName: 'new flavor created',
description: 'triggers when a new icecream flavor is created.',
props: {
dropdown: Property.Dropdown({
displayName: 'Dropdown',
required: true,
refreshers: [],
options: async (_, {connections,project}) => {
const connection = await fetchConnection<AppConnectionType.CUSTOM_AUTH>(connections, (await project.externalId()));
// your logic
return {
options: [{
label: 'test',
value: 'test'
}]
}
}
})
},
sampleData: {},
type: TriggerStrategy.POLLING,
async test({connections, project}) {
const connection = await fetchConnection<AppConnectionType.CUSTOM_AUTH>(connections, (await project.externalId()));
// use the connection with your own logic
return []
},
async onEnable({connections, project}) {
const connection = await fetchConnection<AppConnectionType.CUSTOM_AUTH>(connections, (await project.externalId()));
// use the connection with your own logic
},
async onDisable({connections, project}) {
const connection = await fetchConnection<AppConnectionType.CUSTOM_AUTH>(connections, (await project.externalId()));
// use the connection with your own logic
},
async run({connections, project}) {
const connection = await fetchConnection<AppConnectionType.CUSTOM_AUTH>(connections, (await project.externalId()));
// use the connection with your own logic
return []
},
});
```
</Step>
<Step title="Test Your Piece">
Create a flow in your project and add a step from your piece and test it, you should see it working correctly.
</Step>
</Steps>