Get access token for Azure API for FHIR using Azure CLI
Article
Important
Azure API for FHIR will be retired on September 30, 2026. Follow the migration strategies to transition to Azure Health Data Services FHIR® service by that date. Due to the retirement of Azure API for FHIR, new customer deployments won't be allowed beginning April 1, 2025.
Azure Health Data Services FHIR service is the evolved version of Azure API for FHIR that enables customers to manage FHIR, DICOM, and MedTech services with integrations into other Azure services.
In this article, you learn how to obtain an access token for the Azure API for FHIR® using the Azure CLI. When you provision the Azure API for FHIR, you configure a set of users or service principals that have access to the service. If your user object ID is in the list of allowed object IDs, you can access the service using a token obtained using the Azure CLI.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Obtain a token
The Azure API for FHIR uses a resource or Audience with a URI equal to the URI of the FHIR server https://<FHIR ACCOUNT NAME>.azurehealthcareapis.com. You can obtain a token and store it in a variable (named $token) with the following command.
curl -X GET --header"Authorization: Bearer $token" https://<FHIR ACCOUNT NAME>.azurehealthcareapis.com/Patient
Next steps
In this article, you learned how to obtain an access token for the Azure API for FHIR using the Azure CLI. To learn how to access the FHIR API using REST Client:
Explore the data architecture of FHIR and its API implementation in Azure Health Data Services for Microsoft Cloud for Healthcare and learn about RESTful API framework.
Lists Azure Policy Regulatory Compliance controls available for Azure API for FHIR. These built-in policy definitions provide common approaches to managing the compliance of your Azure resources.
Learn how to troubleshoot identity provider configuration for the FHIR service in Azure Health Data Services, including Azure Active Directory B2C. Use API version 2023-12-01 to configure two non-Microsoft identity providers for scoped access.
These tutorials walk through an example of deploying a simple web application. This section of the tutorial walks through testing connecting to the FHIR server