Get access token for Azure API for FHIR using Azure CLI

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 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'll 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.

Prerequisites

Obtain a token

The Azure API for FHIR uses a resource or Audience with 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:

$token=$(az account get-access-token --resource=https://<FHIR ACCOUNT NAME>.azurehealthcareapis.com --query accessToken --output tsv)

Use with Azure API for FHIR

curl -X GET --header "Authorization: Bearer $token" https://<FHIR ACCOUNT NAME>.azurehealthcareapis.com/Patient

Next steps

In this article, you've 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 Postman, proceed to the Postman tutorial.

FHIR® is a registered trademark of HL7 and is used with the permission of HL7.