Find out what NHS Digital is doing to support the response on our Coronavirus update page.
If you are a patient needing advice visit the coronavirus page on NHS.UK
Overview
This page exaplins how to integrate your software with our OAuth 2.0 authorisation service for RESTful APIs.
In particular, it describes the combined authentication and authorisation pattern which is summarised in user-restricted APIs.
Note: in the steps below, make sure you use the domain name that's appropriate to the environment you're using:
| Environment | Domain name |
|---|---|
| Integration test | int.api.service.nhs.uk |
| Production | api.service.nhs.uk |
1. Create an application
To access a user-restricted RESTful API, you need to create an application. This gives you access to your API Key and Secret, and allows you to specify your Callback URL, all of which you will need later in the process.
- If you don't already have one, create a developer account.
- Navigate to my developer account and sign in.
- Select 'My applications'.
- Select '+ NEW APP'.
- Enter details for your application.
- In the 'APIs' section, find the testing APIs you want to test with and activate them by clicking the slider.
- Enter the Callback URL for your application. See step 4 for more details.
- Select 'CREATE' to create the application.
- Make a note of the API Key and Secret.
6. Call a user-restricted API
Once you have an access token, you can call a user-restricted API.
You need to include the following headers in your call:
Authorization=Bearer <your access token from step 5>NHSD-Identity-JWT= <user ID from step 5>NHSD-Session-URID= <user role ID from step 3>
Here's an example, using a CURL command:
curl -X GET https://sandbox.api.service.nhs.uk/hello/user \
-H "Authorization: Bearer [your access token from step 5]" \
-H "NHSD-Identity-JWT: [user ID from step 5]" \
-H "NHSD-Session-URID: [user role ID from step 3]"
For details of error conditions, please contact us.
7. Refresh token
Access tokens expire after a period of time and must be refreshed.
For details on how to refresh an access token, please contact us.
Requesting a new token
For details on how to request a new token once your token has expired, please contact us.