Bot $deploy
The $deploy operation uploads and activates Bot code on the Medplum server. This is essential for making your automation logic available for
execution by subscriptions, manual invocation, or scheduled tasks.
Deploying bots allows you to version and update your server-side automation without downtime, making it a critical operation for maintaining healthcare workflows in production environments.
Use Cases
- CI/CD Pipelines: Automatically deploy bot updates as part of your continuous deployment workflow
- Development Iteration: Quickly test code changes by deploying updated bot logic during development
- Production Updates: Roll out new features or bug fixes to production bots with minimal disruption
- Multi-Environment Management: Deploy different bot versions across staging and production environments
tip
If you're not familiar with Medplum Bots, you may want to review the Bot Basics documentation first.
Invoke $deploy Operation
To use the $deploy operation, you will need to make a POST request with the Bot's id. Additionally, the $deploy operation takes two body parameters:
filename: The name of the file the bot is stored in. If left blank, it will default toindex.js.code: The bot's code that will be executed when it is run.
- Typescript
- CLI
- cURL
await medplum.post(medplum.fhirUrl('Bot', '[id]', '$deploy').toString(), {
filename: 'hello-patient.js',
// eslint-disable-next-line no-template-curly-in-string
code: "import { BotEvent, MedplumClient } from '@medplum/core';\nimport { Patient } from '@medplum/fhirtypes';\n\nexport async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {\n const patient = event.input as Patient;\n const firstName = patient.name?.[0]?.given?.[0];\n const lastName = patient.name?.[0]?.family;\n console.log(`Hello ${firstName} ${lastName}!`);\n return true;\n}\n",
});
medplum post 'Bot/[id]/$deploy' '{ "filename": "hello-patient.js", "code": "import { BotEvent, MedplumClient } from '@medplum/core';\nimport { Patient } from '@medplum/fhirtypes';\n\nexport async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {\n const patient = event.input as Patient;\n const firstName = patient.name?.[0]?.given?.[0];\n const lastName = patient.name?.[0]?.family;\n console.log(`Hello ${firstName} ${lastName}!`);\n return true;\n}\n" }'
curl 'https://api.medplum.com/fhir/R4/Bot/[id]/$deploy' \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $MY_ACCESS_TOKEN" \
-d '{"filename":"hello-patient.js","code":"import { BotEvent, MedplumClient } from '@medplum/core';\nimport { Patient } from '@medplum/fhirtypes';\n\nexport async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {\n const patient = event.input as Patient;\n const firstName = patient.name?.[0]?.given?.[0];\n const lastName = patient.name?.[0]?.family;\n console.log(`Hello ${firstName} ${lastName}!`);\n return true;\n}\n"}'
Related
- Bot $execute - Execute a deployed bot
- Bots In Production - Deployment best practices and CI/CD setup
- Bot Basics - Introduction to Medplum Bots
- Medplum CLI - Command-line tool for bot deployment
- FHIR Bot Resource - Medplum Bot resource reference