Intro
The Medplum CLI (Command Line Interface) is a set of command line tools to quickly deploy Medplum web applications and Medplum bots.
Prerequisites
The Medplum CLI requires Node.js version 18+
Installation
Add globally:
npm install --global @medplum/cli
Or add as a package dependency:
npm install @medplum/cli
Authentication
Use one of these authentication options:
- Stored credentials in
~/.medplum/credentials
. You can use themedplum login
command (see below) to automatically create this file. - Client credentials in environment variables
MEDPLUM_CLIENT_ID
andMEDPLUM_CLIENT_SECRET
.dotenv
is enabled, so you can store them in a.env
file. - Client credentials in optional command flags.
--client-id <clientId>
- FHIR server client id
--client-secret <clientSecret>
- FHIR server client secret
Usage
If installed globally, you can use the medplum
command directly:
medplum <command> <args>
If installed as a package dependency, you can use the medplum
command via npx
:
npx medplum <command> <args>
By default, the medplum
command uses the Medplum hosted API at "https://api.medplum.com". If you want to use the medplum
command against your own self-hosted server, you can use the MEDPLUM_BASE_URL
environment variable. dotenv
is enabled, so you can store this value in a .env
file.
optional flags for medplum commands
--base-url <baseUrl>
- FHIR server base url
--fhir-url-path <fhirUrlPath>
- FHIR server url path
--tokenUrl <tokenUrl>
- FHIR server token url
--authorizeUrl <authorizeUrl>
- FHIR server authorize url
medplum get --base-url https://api.example.com 'Patient/homer-simpson'
Auth
login
The login
command opens a web browser to a Medplum authentication page.
On successful login, the command writes credentials to disk at ~/.medplum/credentials
.
The medplum
command will then load those credentials on all future runs.
Example:
medplum login
whoami
The whoami
command displays whether the client is authenticated, and, if so, the name of the current user and current Medplum project.
medplum whoami
RESTful Operations
The medplum
command can be used as a convenient tool for basic Medplum CRUD and RESTful operations.
While all API endpoints are available to any command line HTTP client such as curl
or wget
, there are a few advantages to using the medplum
command:
- Authentication and credentials - login once using the
login
command, and theAuthorization
header will be set automatically. - URL prefixes - adds the base URL (i.e., "https://api.medplum.com") and FHIR path prefix (i.e., "fhir/R4/").
- Pretty print - formats the JSON with spaces and newlines.
- Medplum extended mode - adds the
X-Medplum
HTTP header for private Medplum fields.
get
Makes an HTTP GET
request.
medplum get <url>
Example: Search for patients:
medplum get 'Patient?name=homer'
Example: Read patient by ID:
medplum get Patient/$id