|
1 | 1 | # delivery-receipts-api |
2 | 2 |
|
3 | | -The Delivery Receipts API is a [callback handler](https://docs.notifications.service.gov.uk/java.html#callbacks) for consumption by Notify. |
| 3 | +The Delivery Receipts API is a [callback handler](https://docs.notifications.service.gov.uk/java.html#callbacks) for |
| 4 | +consumption by Notify. |
4 | 5 |
|
5 | | -When called by Notify the handler adds a Cloudwatch metric to track how many messages were sent by Notify, whether they were emails or SMS, and which template was used. |
6 | | -The output can be seen in the [Grafana - Authentication - Notify Metrics](https://g-8e26091ad7.grafana-workspace.eu-west-2.amazonaws.com/d/ufjJdaR4z/authentication-notify-metrics?orgId=1) Dashboard. |
| 6 | +When called by Notify the handler adds a Cloudwatch metric to track how many messages were sent by Notify, whether they |
| 7 | +were emails or SMS, and which template was used. |
| 8 | +The output can be seen in |
| 9 | +the [Grafana - Authentication - Notify Metrics](https://g-8e26091ad7.grafana-workspace.eu-west-2.amazonaws.com/d/ufjJdaR4z/authentication-notify-metrics?orgId=1) |
| 10 | +Dashboard. |
7 | 11 |
|
8 | | -At the moment the handler is deployed to both Integration and Production, but is only actually connected to Notify in Production. |
| 12 | +The handler is deployed to both Integration and Production, but is only actually connected to Notify in Production. |
| 13 | + |
| 14 | +Post secure pipeline migration the handler is deployed to and can be tested in all environments. It is not connected to |
| 15 | +Notify, this can be done ad-hoc if required. |
| 16 | +Only one endpoint at a time can be connected to Notify as each account supports a single callback endpoint. |
9 | 17 |
|
10 | 18 | ## Testing the handler |
11 | 19 |
|
12 | | -The handler is not currently deployed to Build or Staging, but can be tested in Sandpit or Integration. |
| 20 | +In the strategic accounts the handler is deployed in all environments. Sandpit has now been removed. |
| 21 | + |
| 22 | +### Testing in the AWS Console |
13 | 23 |
|
14 | 24 | 1. Go to API Gateway in the AWS Console |
15 | 25 | 1. Find the `env-di-authentication-delivery-receipts-api` |
16 | 26 | 1. Click on `POST` under `/notify-callback` |
17 | 27 | 1. Select the 'TEST' tab |
18 | 28 | 1. Go to 'Systems Manager -> Parameter Store' |
19 | | -1. Find the `env-notify-callback-bearer-token` and take a copy of the token |
20 | | -1. Back in the 'TEST' tab in API Gateway, paste in the bearer token as a header in the format `Authorization:Bearer token-value` |
| 29 | +1. Find the `env-notify-callback-bearer-token` and take a copy of the token (requires admin or poweruser) |
| 30 | +1. Back in the 'TEST' tab in API Gateway, paste in the bearer token as a header in the format |
| 31 | + `Authorization:Bearer token-value` |
21 | 32 | 1. Paste the following test json payload data into the body field: |
22 | | - ``` |
23 | | - { |
24 | | - "id": "0qdAiQw2eeF4Xh51etaIwUXc_Ww", |
25 | | - "reference": null, |
26 | | - "to": "n.e.user@digital.cabinet-office.gov.uk", |
27 | | - "status": "delivered", |
28 | | - "created_at": "Wed Sep 20 11:37:41 BST 2023", |
29 | | - "completed_at": "Wed Sep 20 11:37:41 BST 2023", |
30 | | - "sent_at": "Wed Sep 20 11:37:41 BST 2023", |
31 | | - "notification_type": "email", |
32 | | - "template_id": "35454-543543-3435435-12340", |
33 | | - "template_version": 1 |
34 | | - } |
35 | | - ``` |
| 33 | + ``` |
| 34 | + { |
| 35 | + "id": "0qdAiQw2eeF4Xh51etaIwUXc_Ww", |
| 36 | + "reference": null, |
| 37 | + "to": "n.e.user@digital.cabinet-office.gov.uk", |
| 38 | + "status": "delivered", |
| 39 | + "created_at": "Wed Sep 20 11:37:41 BST 2023", |
| 40 | + "completed_at": "Wed Sep 20 11:37:41 BST 2023", |
| 41 | + "sent_at": "Wed Sep 20 11:37:41 BST 2023", |
| 42 | + "notification_type": "email", |
| 43 | + "template_id": "35454-543543-3435435-12340", |
| 44 | + "template_version": 1 |
| 45 | + } |
| 46 | + ``` |
36 | 47 | 1. Click the 'Test' button to test the callback lambda, which will then display the output. |
37 | 48 |
|
| 49 | +### Testing with curl |
| 50 | + |
| 51 | +1. Go to API Gateway in the AWS Console |
| 52 | +1. Find the `env-di-authentication-delivery-receipts-api` |
| 53 | +1. Take a copy of the url for the `/notify-callback` `POST` method under `stages/env` |
| 54 | +1. Go to 'Systems Manager -> Parameter Store' |
| 55 | +1. Find the `env-notify-callback-bearer-token` and take a copy of the token (requires admin or poweruser) |
| 56 | +1. Substitute the url and bearer token then run the following command: |
| 57 | + |
| 58 | +``` |
| 59 | +curl -X POST https://<api-id>.execute-api.eu-west-2.amazonaws.com/<env>/notify-callback \ |
| 60 | + -H "Content-Type: application/json" \ |
| 61 | + -H "Authorization: Bearer your-bearer-token" \ |
| 62 | + -d '{ |
| 63 | + "id": "740e5834-3a29-46b4-9a6f-16142fde533a", |
| 64 | + "reference": "12345678", |
| 65 | + "to": "07700912345", |
| 66 | + "status": "delivered", |
| 67 | + "created_at": "2017-05-14T12:15:30.000000Z", |
| 68 | + "completed_at": "2017-05-14T12:15:30.000000Z", |
| 69 | + "sent_at": "2017-05-14T12:15:30.000000Z", |
| 70 | + "notification_type": "sms", |
| 71 | + "template_id": "97b956c8-9a12-451a-994b-5d51741b63d4", |
| 72 | + "template_version": 1 |
| 73 | + }' |
| 74 | +``` |
38 | 75 |
|
| 76 | +The `template_id` should be a real template id in the Notify account otherwise the api generates an error (the one in |
| 77 | +the body above is a real id in the test account). |
| 78 | +For `"notification_type": "email"` use `"template_id": "a15995f7-94a3-4a1b-9da0-54b1a8b5cc12"` |
0 commit comments