Exercise - Use Dataverse Healthcare APIs with Insomnia
In this exercise, you set up Insomnia to call Dataverse Healthcare APIs to send a Patient FHIR resource bundle to Dataverse and then retrieve data from Dataverse. To complete this exercise, you need to have Insomnia installed locally.
Note
Insomnia introduces the workspace concept to enable you and your team to share APIs, collections, documents, and other components. You can use the default workspace, or create a local or remote workspace for you or your team. In this exercise, you'll create an environment and collection in the default workspace. For more information, see the Insomnia documentation.
Task: Register a Microsoft Entra ID app
In this task, you register a Microsoft Entra ID app to authenticate Insomnia with Dataverse. Grant the Sync Admin for FHIR App Reg User security role to this app so that it can call the Dataverse Healthcare APIs to write to and read from Dataverse. This app uses the implicit grant flow to obtain an access token from Microsoft Entra ID to authenticate Insomnia; hence, you don't need to create a secret for this app. For more information, see Token grant flows.
Follow the steps from Microsoft Cloud for Healthcare training environment preparation to register a Microsoft Entra ID app.
Set up the Microsoft Entra ID app by using the following details:
Name - Lamna Healthcare Integration App
Supported account types - Accounts in this organizational directory only
After registering the Microsoft Entra ID app, copy its Client ID and then provide the following API permission:
API Name - Dynamics CRM
Permissions type - Delegated permissions
Permission - user_impersonation
On the left pane, select Authentication.
On the right pane, select + Add a platform.
Select Web.
On the Configure Web panel, enter the following values and then, select Configure.
Redirect URIs -
https://insomnia.rest/
Select the tokens you would like to be issued by the authorization endpoint - Access tokens (used for implicit flows)
Select Manifest on the left pane to update the allowPublicClient to true in the manifest file.
Select Save.
Task: Grant Microsoft Entra ID app permission on Dataverse
In this task, you grant permission to the registered Microsoft Entra ID app on Dataverse.
While signed in to your Microsoft 365 tenant as global administrator, open a new tab and then go to Microsoft Power Platform admin center.
On the left navigation pane, select Environments.
On the right pane, select Lamna Healthcare environment.
Select Settings from the command bar.
On the Settings page, select Users + permissions > Application users.
Select + New app user.
On the Create a new app user panel, select + Add an app.
On the Add an app from Microsoft Entra ID panel, use the search box to search for Lamna Healthcare Integration App by using its client ID that you copied in a previous step.
Select Lamna Healthcare Integration App and then select Add.
After adding the Microsoft Entra ID app, you'll be redirected to the Create a new app user panel. Select the ID from the Business unit dropdown menu, and then select the edit icon beside the Security role option.
In the Add security roles pane, select Sync admin for FHIR App Reg User, and then select Save.
You're redirected to the Create a new app user panel. Select Create to add Lamna Healthcare Integration App as an application user and then assign it the Sync admin for FHIR App Reg User security role.
Task: Get a Dataverse access token by using the Implicit grant type
In this task, you set up Insomnia to use Dataverse Healthcare API.
Install Insomnia on your computer, and launch the application. For more information, see Install Insomnia.
Select the settings icon next to Base environment.
Enter Dataverse-Healthcare-APIs as the name for the new environment.
Add the following variables in the Dataverse-Healthcare-APIs environment, and then select Save.
client_id - Enter the client ID of the Lamna Healthcare Integration App that you copied previously
url -
https://<Dataverse-environment-name>.api.crm.dynamics.com
callback -
https://insomnia.rest/
authurl:
https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}}
Select the + icon and select HTTP request.
Name the request to GetDataverseAccessToken.
Select Auth tab and then set up authentication type as OAuth 2.0
On the right pane, in the Configure New Token section, fill in the following details:
Grant Type - Implicit
Authorization URL - Enter {{authurl}}
Client ID - Enter {{client_id}}
Redirect URL - Enter {{callback}}
Scroll down and select Fetch token. At the prompt, select Accept.
After the Fetch token completes, you can view the token in the following section:
Important
You can also use the Client Credential grant flow to obtain an access token from Microsoft Entra ID to authenticate Insomnia. To do so, follow these steps:
Register a Microsoft Entra ID app.
Create a client secret for the app.
Grant the Microsoft Entra ID app with the Sync admin for FHIR APP Reg User permission on Dataverse.
In Insomnia, on the right pane in the Configure New Token section, use the following values:
Grant Type - Client Credentials
Access Token URL -
https://login.microsoftonline.com/{{tenant_id}}/oauth2/v2.0/token
Client ID - Enter the Client ID of the registered Microsoft Entra ID app
Client Secret - Enter the Client Secret of the registered Microsoft Entra ID app
Scope -
https://<Dataverse-env>.crm.dynamics.com/.default
Use the msind_UpsertBundle API
In this task, you use the msind_UpsertBundle API to create a record in the Contact entity of Dataverse. You use the Patient FHIR resource bundle as JSON payload.
Create a new HTTP request.
Name the new request to msind_UpsertBundle_Patient as you're posting the Patient FHIR bundle to the endpoint.
Select POST as the HTTP operation type.
Set the request URL to
https://<Dataverse-environment-name>.crm.dynamics.com/api/data/v9.1/msind_UpsertBundle
.In the Bearer tab,
- Select Token - Paste the token from the previous task.
Note
You can use the /api/data/v9.1/msind_UpsertBundle or the /api/data/v9.2/msind_UpsertBundle endpoint in your API call.
Select the Headers tab and then add the following two request headers:
Content-Type - application/json; charset=utf-8
OData-Version - 4.0
Select the Body tab.
Select JSON.
Use the following FHIR bundle as JSON payload.
{ "msind_BundleTag": "PatientDatatest", "msind_JSON": "{\"resourceType\":\"Bundle\",\"type\":\"batch\",\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"b7777777-b777-b777-b777-b77777777777\",\"text\":{\"status\":\"generated\"},\"identifier\":[{\"system\":\"https://github.com/synthetichealth/synthea\",\"value\":\"51978986-f824-43da-b69a-d2d17f49df70\"}],\"name\":[{\"use\":\"official\",\"family\":\"Contoso\",\"given\":[\"Allen\"],\"prefix\":[\"Ms.\"]}],\"telecom\":[{\"system\":\"phone\",\"value\":\"555-664-6121\",\"use\":\"home\"}],\"gender\":\"female\",\"birthDate\":\"1965-11-04\",\"address\":[{\"extension\":[{\"url\":\"http://hl7.org/fhir/StructureDefinition/geolocation\",\"extension\":[{\"url\":\"latitude\",\"valueDecimal\":42.605887766784662},{\"url\":\"longitude\",\"valueDecimal\":-71.0695322588603}]}],\"line\":[\"165 Shanahan View\"],\"city\":\"North Reading\",\"state\":\"Massachusetts\",\"country\":\"US\"}],\"multipleBirthBoolean\":false},\"request\":{\"method\":\"POST\",\"url\":\"Patient\"}}]}" }
Select Send.
After successful implementation of the API request, Dataverse will respond with the HTTP Status code 200 OK.
Verify the new patient record in Dataverse, go to Microsoft Power Apps portal, and then select your environment.
Select Dataverse > Tables > Contact entity to find the newly created patient record.
Use the msind_RetrieveBundle API
In this task, you use Insomnia to call the msind_RetrieveBundle Dataverse Healthcare API. This API accepts FHIRResource/ID to look for the respective FHIR resource in Dataverse, and if found, it returns the resource with HTTP Status code 200.
Create a new HTTP request.
Name the new request to msind_RetrieveBundle_Patient because you're fetching the Patient FHIR resource from Dataverse.
Select POST as the HTTP operation type.
Set the request URL to
https://<Dataverse-environment-name>.crm.dynamics.com/api/data/v9.1/msind_RetrieveBundle
.Set up the authentication as mentioned in the previous Task - Get a Dataverse access token by using the Implicit grant type.
Note
You can use the /api/data/v9.1/msind_RetrieveBundle or the /api/data/v9.2/msind_RetrieveBundle endpoint in your API call.
Select the Headers tab and then add the following two request headers:
Content-Type - application/json; charset=utf-8
OData-Version - 4.0
Select the Body tab.
Select JSON.
Use the following FHIR bundle as JSON payload.
{ "msind_FHIRQuery": "Patient/b7777777-b777-b777-b777-b77777777777" }
Select Send.
On successful implementation of the API request, Dataverse responds with the HTTP Status code 200 OK.
You successfully used the Dataverse Healthcare APIs by using Insomnia to create a new record in the Contact entity in Dataverse, and then you retrieved the newly created entity from Dataverse.