# API key authentication not working?

**URL:** <https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106>\
**Category:** Personal Demographics Service (PDS)\
**Tags:** pds, spine\
**Created:** [7 November 2024 11:00 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106 "2024-11-07T11:00:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iminshall](https://avatars.discourse-cdn.com/v4/letter/i/a5b964/32.png) [@iminshall](https://developer.community.nhs.uk/u/iminshall)\
**Post date:** [7 November 2024 11:00 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/1 "2024-11-07T11:00:31Z")

</div>

I am trying to call the PDS API using api key authentication as outlined in

[Application-restricted RESTful APIs - API key authentication - NHS England Digital](https://digital.nhs.uk/developer/guides-and-documentation/security-and-authorisation/application-restricted-restful-apis-api-key-authentication).

Each time I do it I get an operation outcome that says ‘Missing Authorization header’. Why do I need an authorization header if you are using api key authentication?

API Key authentication seems to work ok with the Organisation Data Terminology API

---

<div class="post-metadata">

**Author:** ![LRS](https://dub1.discourse-cdn.com/nhsdigitaldeveloper/user_avatar/developer.community.nhs.uk/lrs/32/171_2.png) [@LRS](https://developer.community.nhs.uk/u/LRS)\
**Post date:** [12 November 2024 18:17 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/2 "2024-11-12T18:17:16Z")

</div>

Can you include an example post request?

---

<div class="post-metadata">

**Author:** ![iminshall](https://avatars.discourse-cdn.com/v4/letter/i/a5b964/32.png) [@iminshall](https://developer.community.nhs.uk/u/iminshall)\
**Post date:** [13 November 2024 08:34 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/3 "2024-11-13T08:34:27Z")

</div>

From Postman…

GET /personal-demographics/FHIR/R4/Patient/9449305889 HTTP/1.1

NHSD-Session-URID: 1234567  
X-Request-ID: 8a39e066-557a-48ca-90e5-423e2d575300  
X-Correlation-ID: f1b80841-ac3b-4434-a953-e9e3dd802b7d  
NHSD-End-User-Organisation-ODS: RR8  
Accept: application/fhir+json  
apikey:   
User-Agent: PostmanRuntime/7.42.0  
Cache-Control: no-cache  
Host: [int.api.service.nhs.uk](http://int.api.service.nhs.uk)  
Accept-Encoding: gzip, deflate, br  
Connection: keep-alive

HTTP/1.1 401 Unauthorized  
Date: Wed, 13 Nov 2024 08:31:55 GMT  
Content-Type: application/json  
Content-Length: 587  
Connection: keep-alive  
WWW-Authenticate: Bearer realm=“null”,error=“invalid\_token”,error\_description=“oauth.v2.InvalidAccessToken: Invalid access token”  
X-Correlation-ID: f1b80841-ac3b-4434-a953-e9e3dd802b7d  
X-Request-ID: 8a39e066-557a-48ca-90e5-423e2d575300  
Strict-Transport-Security: max-age=31536000; includeSubDomains

{  
“resourceType”: “OperationOutcome”,  
“issue”: [  
{  
“severity”: “error”,  
“code”: “forbidden”,  
“details”: {  
“coding”: [  
{  
“system”: “[https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode](https://fhir.nhs.uk/R4/CodeSystem/Spine-ErrorOrWarningCode)”,  
“version”: “1”,  
“code”: “ACCESS\_DENIED”,  
“display”: “Access Denied - Unauthorised”  
}  
]  
},  
“diagnostics”: “Missing Authorization header”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![david.hamill1](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@david.hamill1](https://developer.community.nhs.uk/u/david.hamill1)\
**Post date:** [13 November 2024 11:31 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/4 "2024-11-13T11:31:54Z")

</div>

Hi,

Thanks for you patience with this.

Unfortunately, the documentation was recently edited, adding this security pattern erroneously.

Due to the sensitive and personal nature of the data returned in this API, your app can only use the “signed JWT authentication” pattern in restricted access mode.

I have logged a ticket for the documentation to be corrected.

Thanks

---

<div class="post-metadata">

**Author:** ![iminshall](https://avatars.discourse-cdn.com/v4/letter/i/a5b964/32.png) [@iminshall](https://developer.community.nhs.uk/u/iminshall)\
**Post date:** [13 November 2024 12:09 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/5 "2024-11-13T12:09:21Z")

</div>

No worries. Thanks for the update.

---

<div class="post-metadata">

**Author:** ![david.hamill1](https://avatars.discourse-cdn.com/v4/letter/d/f475e1/32.png) [@david.hamill1](https://developer.community.nhs.uk/u/david.hamill1)\
**Post date:** [13 November 2024 14:38 UTC](https://developer.community.nhs.uk/t/api-key-authentication-not-working/3106/6 "2024-11-13T14:38:59Z")

</div>

This change has now been made and the published documentation should reflect this within the hour.
