-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmesh-api.yaml
More file actions
2930 lines (2675 loc) · 123 KB
/
mesh-api.yaml
File metadata and controls
2930 lines (2675 loc) · 123 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.2
info:
title: Message Exchange for Social Care and Health - REST API
description: |-
## Overview
You interact with MESH by making calls to this API from your application.
With the API, you can:
- check the number of messages in your inbox
- send a message, or a larger message as series of chunks
- download a message, or a larger message which was sent to you as a series of chunks
- acknowledge the successful download of a message, which removes it from your inbox
- get the identifiers of messages in your inbox that are ready for download
- track the status of messages that you sent from your outbox
- look up the mailbox of an organisation you want to send data to
- validate your mailbox every 24 hours to let Spine know it's still active
## Who can use this API
This API can only be used where there is a legal basis to do so. We'll ask you to demonstrate this as part of the digital onboarding process before your software goes live.
## Requirements for using this API
There are 2 parts to getting the MESH API, these are:
1. developing and integrating your software
2. getting your software approved to go live
### 1. Developing and integrating your software
You'll need some things at different stages of your development to integrate with the MESH API.
For each environment you use, you'll need a:
- MESH mailbox ID and password
- Transport Layer Security (TLS) certificate
- shared secret to include in the MESH authorization header
### 2. Getting your software approved to go live
This is also called digital onboarding. You'll need to submit information that demonstrates:
- you have a valid use case
- you can manage risks
- your software conforms technically with the requirements for this API
## End-to-end process to integrate with MESH API
The length of time it takes to get your software live depends on the resources your organisation puts into:
- developing your software
- getting things you need for your integration like TLS certificates
- completing onboarding processes and waiting for approval
You can do some things while you wait, but expect the end-to-end integration process to take 1 month or more.
### Get started
To get started, sign in or create a developer account for digital onboarding, complete the 'Setup and eligibility' section and submit it.
If you're new to digital onboarding, add your product and select 'MESH' from the 'APIs to be used' list.
Submitting this information shows us that you have a legal basis to use the MESH API. We'll review the information you submit and respond within 5 to 10 working days.
If we approve your request to use the MESH API, we'll also email you a supplier pack within 10 working days. Read through this as it contains the testing requirements you'll need to fulfil later on.
You should get your use case approved before you go too far with development. You can choose to proceed with your integration while you wait for approval, but you'll be doing this at your own risk.
[Sign in or create a developer account for digital onboarding](https://onboarding.prod.api.platform.nhs.uk)
You will receive a response within 10 working days.
If you have been approved to use the MESH API, our assurance team will contact you via email with a supplier pack containing the testing requirements you will need to fulfill. You will work alongside this team to get your solution assured.
### Request a mailbox
Once we've approved your request to use the MESH API, you'll need to request a MESH Mailbox to use in a 'Path to Live integration environment'. This is how you'll interact with the MESH API. A MESH Mailbox is secure and only your organisation can access it.
To request a MESH Mailbox, you'll need to fill in an online form. It takes 5 to 10 minutes to complete.
You'll need to know:
- your [ODS code](https://odsportal.digital.nhs.uk/)
- the [workflow groups or IDs](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/workflow-groups-and-workflow-ids) for the files you plan to send or receive
- the contact details of the person who will be managing the mailbox in your organisation
[Request a 'Path to Live integration' MESH Mailbox](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/messaging-exchange-for-social-care-and-health-apply-for-a-mailbox)
### Receive your credentials for the 'Path to Live integration' environment
Once you've requested a MESH Mailbox, we will email you your Mailbox ID and password within 5 working days. Keep these details safe as we'll also ask you for this if you need help from our support teams.
You will also receive the shared secret. You'll need to include this in the [MESH authorization header](#overview--mesh-authorization-header) when you develop this part of your software.
### Get a TLS certificate
You'll need a TLS certificate to establish a secure connection to MESH.
How to get a TLS certificate
1. Generate a private key using your preferred method, with the naming convention cn=mailboxid.odscode.api.mesh-client.nhs.uk
2. Generate a certificate signing request (CSR) based on the private key and your Mailbox ID.
3. Email the CSR to [itoc.supportdesk@nhs.net](mailto:itoc.supportdesk@nhs.net) - this needs to contain the common name from your CSR 'Subject' using the format local_id.ods_code.api.mesh-client.nhs.uk
The local_id is a local identifier such as a server name and ods_code is your ODS code, for example, SERVER001.X26.api.mesh-client.nhs.uk.
Once we receive your CSR, we'll send you a TLS certificate within 5 working days.
Depending on how you implement MESH API, you may also need to [download a RootCA and SubCA certificate](https://digital.nhs.uk/services/path-to-live-environments/integration-environment#rootca-and-subca-certificates). These are also required to establish a secure connection.
### Develop and test your software
Now that you have a MESH Mailbox for a 'Path to Live integration' environment and a TLS certificate, start developing your software using the MESH API.
When you're ready to go live, you'll need to:
- request a TLS certificate for the production environment
- request a MESH mailbox for the production environment
- get a conformance certificate
- sign a connection agreement
### Submit non-functional requirements
Once you've developed your software, you'll need to answer some questions in digital onboarding about the processes you use for:
- handling data securely
- managing clinical risk
- using our production environment
This shows that your software meets our non-functional requirements.
[Sign in to the digital onboarding to answer questions on 'non-functional' requirements](https://onboarding.prod.api.platform.nhs.uk)
### Demonstrate technical conformance
Before you can go live, in digital onboarding, you'll need to:
- answer some questions to show you conform to the technical requirements of our APIs
- upload a conformance certificate
To get a technical conformance certificate, you'll need to complete the testing requirements in the supplier pack we sent to you.
Some of these tests have to be witnessed by us. To arrange a witness test, reply to the email that contains the supplier pack. The witness testing takes 2 to 3 hours.
In some cases, we may ask you to prepare test data a few days before the day of the witness testing.
When you've completed a witness test, we'll email a technical conformance certificate to you within 5 working days. You can then upload it to digital onboarding.
[Sign in to the digital onboarding to upload a technical conformance certificate](https://onboarding.prod.api.platform.nhs.uk)
### Get a MESH Mailbox for your live software
When you're ready to send or receive real data, you'll need a MESH Mailbox in the production environment. We'll ask to see the conformance certificate for your software before we issue this.
MESH Mailboxes are specific to environments, this means you'll need a different MESH Mailbox ID for each environment you use.
To request a MESH Mailbox, you'll need to fill in an online form. It takes 5 to 10 minutes to complete.
You'll need to know:
- your [ODS code](https://odsportal.digital.nhs.uk/)
- the [workflow groups or IDs](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/workflow-groups-and-workflow-ids) for the files you plan to send or receive
- the contact details of the person who will be managing the mailbox in your organisation
[Request a 'Live' MESH Mailbox](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/messaging-exchange-for-social-care-and-health-apply-for-a-mailbox)
### Get a TLS certificate for the production environment
Once you have a Mailbox ID, you'll need to get a TLS certificate. This allows you to establish a secure connection to MESH in the production environment.
How to get a TLS certificate
1. Generate a private key using your preferred method, with the naming convention cn=mailboxid.odscode.api.mesh-client.nhs.uk
2. Generate a CSR based on the private key and your Mailbox ID
3. Email the CSR and technical conformance certificate to [ssd.nationalservicedesk@nhs.net](mailto:ssd.nationalservicedesk@nhs.net) - this needs to contain the common name from your CSR 'Subject' using the format local_id.ods_code.api.mesh-client.nhs.uk
The local_id is a local identifier such as a server name and ods_code is your ODS code, for example, SERVER001.X26.api.mesh-client.nhs.uk.
Once we receive your CSR and technical conformance certificate, we'll send you a TLS certificate for the production environment within 5 working days.
Depending on how you implement MESH API, you may also need to [download a RootCA and SubCA certificate](https://digital.nhs.uk/services/path-to-live-environments/integration-environment#rootca-and-subca-certificates). These are also required to establish a secure connection.
### Sign connection agreement
You'll need to sign a connection agreement before your software can go live. Once you've signed it, you need to upload it to the 'Legal agreement' section in digital onboarding. We'll email your connection agreement to you within 5 working days of completing your witness test.
[Sign in to the digital onboarding to upload your connection agreement](https://onboarding.prod.api.platform.nhs.uk)
### Go live with your software
You have now completed all integration and onboarding steps. This means you can use the MESH API with your live software.
## Related APIs
A number of our APIs are messaging APIs that use MESH as the transport layer. For a full list, see [our API catalogue, filtered on MESH APIs](https://digital.nhs.uk/developer/api-catalogue?filter=mesh).
In particular, this includes [National Event Management Service - FHIR API](https://digital.nhs.uk/developer/api-catalogue/national-events-management-service-fhir) -
our API for publishing and subscribing to healthcare events such as updates to patient demographic details.
## API status and roadmap
This API is [in production](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#statuses).
## Service level
This API is a platinum service, meaning it is operational and supported 24 hours a day, 365 days a year.
For more details, see [service levels](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#service-levels).
## Technology
This API is [RESTful](https://digital.nhs.uk/developer/guides-and-documentation/api-technologies-at-nhs-digital#basic-rest).
## Network access
This API is available on the internet.
For more details see [Network access for APIs](https://digital.nhs.uk/developer/guides-and-documentation/network-access-for-apis).
## Errors
We use standard HTTP status codes to show whether an API request succeeded or not. They are usually in the range:
* 200 to 299 if it succeeded, including code 202 if it was accepted by an API that needs to wait for further action
* 400 to 499 if it failed because of a client error by your application
* 500 to 599 if it failed because of an error on our server
Errors specific to each API are shown in the Endpoints section, under Response. See our [reference guide](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#http-status-codes) for more on errors.
## Open source
We have a number of open source resources that you might find useful:
| Resource | Description | Links |
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| MESH sandbox | For early developer testing, a realistic MESH experience that runs locally in docker or as an embedded python package. For more details, see 'Environments and testing' below. | [GitHub repo](https://github.com/NHSDigital/mesh-sandbox) \| [Python Package Index](https://pypi.org/project/mesh-sandbox/) |
| MESH Python client | A fully-featured Python client library that conforms to our technical integration requirements. This is not the same as the MESH Java client. | [GitHub repo](https://github.com/NHSDigital/mesh-client) \| [Python Package Index](https://pypi.org/project/Mesh-Client) |
| MESH AWS Serverless client | A fully-featured MESH client built using terraform and AWS serverless components. | [GitHub repo](https://github.com/NHSDigital/terraform-aws-mesh-client) |
| MESH Validate Auth Header | A tool for validating the construction of the MESH authentication token. | [GitHub repo](https://github.com/NHSDigital/mesh_validate_auth_header) \| [GitHub pages UI](https://nhsdigital.github.io/mesh_validate_auth_header/#/) |
For more details, see [open source](https://digital.nhs.uk/developer/guides-and-documentation/reference-guide#open-source).
## Environments and testing
There are multiple externally accessible instances of MESH that can be used for testing, each with a different root URL.
| Purpose | Network availability | URL |
|---------------|----------------------|-------------------------------------------|
| Integration | Internet | `https://msg.intspineservices.nhs.uk/` |
| Production | Internet | `https://mesh-sync.spineservices.nhs.uk/` |
**Note** - each environment has the same shared secret but requires different client TLS certificates.
For any questions about our testing environments, contact our support mailbox [itoc.supportdesk@nhs.net](mailto:itoc.supportdesk@nhs.net).
### Develop against a local MESH sandbox server
There is a basic sandbox implementation of the MESH API available [mesh-sandbox](https://github.com/NHSDigital/mesh-sandbox).
This sandbox can be used for local development and currently does not require a client certificate
## API Versioning
MESH API now has `live-beta` support for versioning on certain endpoints in order to allow us to safely make new features and capabilities available to API consumers.
MESH uses the `Accept` header to support different versions in the same API, sending a different `Accept` header will vary the response, refer to individual API endpoints for more detail.
If not specified `Accept: application/json` will be assumed and the lowest supported response version for that particular endpoint will be returned.
**Note:** please refer to the table below for more detail on the status of a given API version.
| Version | Accept | Status |
|---------|------------------------------------------------------|--------|
| 1 | `application/json` or `application/vnd.mesh.v1+json` | live |
| 2 | `application/vnd.mesh.v2+json` | live |
## MESH Authorization header
Requests to the MESH API require an authorisation token in the HTTP `Authorization` header.
To be valid, the authorisation token must match the schema described below. The token includes cryptographic hashes of your organisation's MESH mailbox password and the environment-wide shared secret.
As an additional security measure each token which matches the schema is valid for one request only, so you must generate a new token for every request. Any repeated use of a token results in a `403: Not Authorized` response from the MESH API.
The authorisation token is made up of six elements. Except for the first and second elements, each element is separated from the next by a colon (:).
| Name | Description |
|---------------|------------------------------------------------------------------------------------------------|
| `NHSMESH` | The name of the Custom Authentication Schema. The space at the end of the schema is important. |
| `mailbox_id` | The mailbox identifier sending the HTTP Request. Must be uppercase. |
| `nonce` | A GUID used as an encryption nonce. |
| `nonce_count` | The number of times that the same nonce has been used. |
| `timestamp` | The current UTC date and time in `yyyyMMddHHmm` format. |
| `hash` | HMAC-SHA256 hash - see the list below. |
The `hash` is compiled of the following items:
* The `shared_key` is the MESH environment shared secret, provided by [itoc.supportdesk@nhs.net](mailto:itoc.supportdesk@nhs.net) as part of onboarding to the PTL environment.
* The `message` is the concatenation of the 5 following elements, joined by a colon (:):
- `mailbox_id`
- `nonce`
- `nonce_count`
- `mailbox_password`
- `timestamp`
Changing the `nonce` and/or `nonce_count` elements between requests ensures the Authorization header is unique and valid.
**Notes**
- the API rejects the request if the `timestamp` supplied is not within 2 hours of the server time
- in the example below `SHARED_KEY` has been `[REDACTED_SHARED_KEY]`, this is the 'environment shared secret' which you received as part of creating your mailbox
- in the example below `MAILBOX_PASSWORD` has been `[REDACTED_PASSWORD]`, this is the 'mesh mailbox password' which you received as part of creating your mailbox
### Example implementation
Here is an implementation of the above in `python3`.
```python
""" Python code to generate a valid authorization header. """
import hmac
import uuid
import datetime
from hashlib import sha256
AUTH_SCHEMA_NAME = "NHSMESH " # Note: Space at the end of the schema.
SHARED_KEY = "[REDACTED_SHARED_KEY]" # Note: Don't hard code your passwords in a real implementation.
def build_auth_header(mailbox_id: str, password: str = "password", nonce: str = None, nonce_count: int = 0):
""" Generate MESH Authorization header for mailboxid. """
# Generate a GUID if required.
if not nonce:
nonce = str(uuid.uuid4())
# Current time formatted as yyyyMMddHHmm
# for example, 4th May 2020 13:05 would be 202005041305
timestamp = datetime.datetime.utcnow().strftime("%Y%m%d%H%M")
# for example, NHSMESH AMP01HC001:bd0e2bd5-218e-41d0-83a9-73fdec414803:0:202005041305
hmac_msg = mailbox_id + ":" + nonce + ":" + str(nonce_count) + ":" + password + ":" + timestamp
# HMAC is a standard crypto hash method built in the python standard library.
hash_code = hmac.HMAC(SHARED_KEY.encode(), hmac_msg.encode(), sha256).hexdigest()
return (
AUTH_SCHEMA_NAME # Note: No colon between 1st and 2nd elements.
+ mailbox_id + ":"
+ nonce + ":"
+ str(nonce_count) + ":"
+ timestamp+ ":"
+ hash_code
)
# example usage
MAILBOX_ID = "X26AB1234" # Note: Don't hard code your mailbox id in a real implementation.
MAILBOX_PASSWORD = "[REDACTED_PASSWORD]" # Note: Don't hard code your passwords in a real implementation.
# send a new nonce each time
print(build_auth_header(MAILBOX_ID, MAILBOX_PASSWORD))
# or reuse the nonce and increment the nonce_count
my_nonce = str(uuid.uuid4())
print(build_auth_header(MAILBOX_ID, MAILBOX_PASSWORD, my_nonce, nonce_count=1))
print(build_auth_header(MAILBOX_ID, MAILBOX_PASSWORD, my_nonce, nonce_count=2))
```
## MESH API pseudocode
To use MESH effectively, use the following flow of API calls:
- inbox poll cycle
- outbox workflow
Validate your mailbox once every 24 hours using the 'Validate a mailbox' endpoint.
### Inbox poll cycle
Spine gives each message a unique message identifier after you post it to your outbox. It is the primary identifier for the message during MESH transit.
It is suggested to poll your mailbox every 5 minutes, but at least every 24 hours. The pseudocode for a mailbox poll is:
1. Poll to get the messageIds of messages ready to download from the 'Check an inbox' endpoint.
2. For each message identifier returned in step 1:
* download the message with the 'Download message' endpoint
* if it's identified as a chunked message, download all remaining chunks with the 'Download message chunk' endpoint
* acknowledge receipt of the message via the 'Acknowledge message' endpoint
3. Repeat step 2 until you have processed the number of messages returned in step 1.
4. If you received exactly 500 messages in step 1 then repeat from step 1, immediately polling again and downloading, until you receive 0 messages in step 1.
### Asynchronous error reporting
Most problems with message transfer are indicated synchronously (immediately) when you call the 'Send Message' endpoint. However, some errors might occur after a successful request (asynchronously). You get any error reports as messages in your inbox, which you need to receive as part of your inbox poll cycle.
Error reports differ from regular messages in these ways:
- the 'Download message endpoint' has a different value for the `Mex-MessageType` header:
* DATA for a normal organisation-to-organisation message
* REPORT for an error report
- the Download message response body of an error report message is empty
We strongly recommend you check the value of `Mex-MessageType` after downloading each message, so that you can take appropriate action if needed.
| Error Report Header | Description |
|-------------------------|--------------------------------------------------------------------------|
| `Mex-StatusEvent` | Step in the MESH server side process when the error occurred |
| `Mex-LinkedMsgID` | The message identifier of the undelivered message |
| `Mex-WorkflowID` | The workflow identifier of the undelivered message |
| `Mex-StatusTimestamp` | Time the error occurred |
| `Mex-LocalID` | Sender assigned local identifier of the unacknowledged message |
| `Mex-StatusCode` | Indicate the status of the message, non-00 indicates error |
| `Mex-MessageID` | The message identifier of the error report (not the undelivered message) |
| `Mex-StatusSuccess` | SUCCESS or ERROR (is always ERROR in an error report) |
| `Mex-StatusDescription` | Indicate the status the message, non-00 indicates error |
| `Mex-To` | Intended receiver of the undelivered message |
| `Mex-MessageType` | REPORT |
| `Mex-Subject` | The subject of the undelivered message |
**Note:** Headers should be treated case insensitively, most http clients will do this for you automatically, but please do not rely on explicit case.
### Error codes
Some of the below errors are only applicable for some API calls. For example, error code 15 would only be found when calling 'Child Protection Information Services' (CP-IS).
| Error code | Typical description |
|------------|---------------------------------------------------------------------------|
| 02 | Data file is missing or inaccessible |
| 06 | Malformed headers |
| 07 | Invalid From Address, the mailbox does not match the authorization header |
| 08 | Missing Mex-To header |
| 11 | Invalid Message Type for the transfer, should be DATA |
| 12 | Unregistered to address |
| 14 | Undelivered message |
| 15 | Bad 'Child Protection - Information Sharing' (CP-IS) File |
| 16 | Sender is not allowed to send messages of this type |
| 17 | Workflow ID not registered for mailbox |
### Outbox workflow
The maximum amount of data allowed by MESH in a single request message is 100MB. You can send larger messages by breaking them into \"chunks\" that are transmitted as a single message over multiple requests. The upper limit of a single chunked message is 100GB (20GB if using the java client).
The [MESH UI](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/compare-mesh-services#mesh-user-interface) and older versions of the MESH client do not support chunking. Check that the receiver's interface to MESH for your workflow identifier handles chunked messages prior to sending. To do this:
1. Determine the size of your message data (after compression) with a standard algorithm (such as `gzip`). If the compressed message is larger than 100MB, is smaller than 100GB, and the receiving mailbox / workflow identifier supports chunking, then you can send a chunked message. To prepare for this:
* split the **uncompressed** data into ordered chunks
* **independently** compress each chunk with the **same** compression algorithm (such as `gzip`) such that each chunk is smaller than 100MB
* use the first chunk (after compression) as the initial message data
2. Send a message with appropriate workflow identifier and `Mex-To` (recipient mailbox) header. To do this:
* optionally include a local identifier from step 2 for tracking. This field must not contain PID.
* if sending a chunked message, include an extra header to indicate that this is the first in a series of chunks, then submit the subsequent chunks via the 'Send Chunked Message' endpoint
3. A message identifier will be returned which is the unique identifier and can be used for tracking and helping with incident resolution. It would be good practice to log this identifier.
### Message expiration
Messages that are not downloaded and acknowledged within five days of delivery are removed from your inbox. The sending organisation receives an error report explaining that the receiver did not collect the message. Uncollected messages are completely deleted from the MESH server 30 days after the initial delivery. If the sending organisation cannot re-send the message within the intervening time, it may contact our [national service desk](https://digital.nhs.uk/developer/help-and-support) with the error report details and ask for the message to be placed in your inbox again.
## Onboarding
You need to get your software approved by us before it can go live with this API. We call this onboarding. The onboarding process can sometimes be quite long, so it's worth planning well ahead.
You can view a read-only version of the digital application form on the <a href="https://onboarding.prod.api.platform.nhs.uk/Products/PreviewOverview?apiId=34">MESH assurance questions</a> page.
To understand how our online digital onboarding process works, see [digital onboarding](https://digital.nhs.uk/developer/guides-and-documentation/digital-onboarding). This is where you can demonstrate that you can manage risks and that your software conforms technically with the requirements for this API. You can also manage onboarding for other APIs in your account.
<div class="nhsd-m-emphasis-box nhsd-m-emphasis-box--emphasis nhsd-!t-margin-bottom-6" aria-label="Highlighted Information">
<div class="nhsd-a-box nhsd-a-box--border-blue">
<div class="nhsd-m-emphasis-box__image-box">
<figure class="nhsd-a-image">
<picture class="nhsd-a-image__picture">
<img src="http://digital.nhs.uk/binaries/content/gallery/icons/play-circle.svg?colour=231f20" alt="" style="object-fit:fill">
</picture>
</figure>
</div>
<div class="nhsd-m-emphasis-box__content-box">
<div data-uipath="website.contentblock.emphasis.content" class="nhsd-t-word-break">
<p class="nhsd-t-body">To get started, sign in or create a <a href="https://onboarding.prod.api.platform.nhs.uk/">developer account</a>, then select 'product onboarding'.</p>
</div>
</div>
</div>
</div>
## Contact us
For help and support connecting to our APIs and to join our developer community, see [Help and support building healthcare software](https://digital.nhs.uk/developer/help-and-support).
contact:
name: National Service Desk
email: ssd.nationalservicedesk@nhs.net
version: 2.0.0
paths:
/messageexchange/{mailbox_id}:
post:
tags:
- Handshake
summary: Validate a mailbox (Handshake)
description: |-
## Overview
Use this endpoint to check that MESH can be reached and that the authentication you are using is correct. This endpoint only needs to be called once every 24 hours.
This endpoint updates the details of the connection history held for your mailbox and is similar to a keep-alive or ping message, in that it allows monitoring on the Spine to be aware of the active use of a mailbox despite a lack of traffic.
### Request
```shell
curl -k \
--request 'GET' \
--cacert 'mesh-ca.pem' \
--key 'mesh-client-key.pem' \
--cert 'mesh-client-cert.pem' \
--header 'accept: application/vnd.mesh.v2+json' \
--header 'authorization: NHSMESH X26HC005:1c820cd4-be3e-43ff-807f-e65362892722:0:202006041718:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced' \
--header 'mex-clientversion: ApiDocs==0.0.1' \
--header 'mex-osarchitecture: x86_64' \
--header 'mex-osname: Linux' \
--header 'mex-osversion: #44~18.04.2-Ubuntu' \
https://mesh-sync.spineservices.nhs.uk/messageexchange/X26HC005
```
operationId: handshake_messageexchange__mailbox_id__post
parameters:
- description: mailbox identifier
required: true
schema:
title: mailbox_id
minLength: 1
type: string
description: mailbox identifier
example: MAILBOX01
name: mailbox_id
in: path
- description: User agent string
required: false
schema:
title: User-Agent
type: string
description: User agent string
default: ''
example: my-client;windows-10;
name: user-agent
in: header
- description: Client version number
required: true
schema:
title: mex-ClientVersion
type: string
description: Client version number
example: ApiDocs==0.0.1
name: mex-clientversion
in: header
- description: Operating system name
required: true
schema:
title: mex-OSName
type: string
description: Operating system name
example: Linux
name: mex-osname
in: header
- description: Operating system version
required: true
schema:
title: mex-OSVersion
type: string
description: Operating system version
example: '#44~18.04.2-Ubuntu'
name: mex-osversion
in: header
- description: Authorisation header
required: true
schema:
title: Authorization
type: string
description: Authorisation header
example: 'authorization: NHSMESH NONFUNC01:2c001608-5f09-4840-9611-bea43e666a30:1:201511201038:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced'
name: authorization
in: header
- description: the accepts header can be used to vary the response type
required: false
schema:
title: Accept
type: string
description: the accepts header can be used to vary the response type
default: application/json
example: application/vnd.mesh.v2+json
name: accept
in: header
responses:
'200':
description: Successful Response
'400':
description: Validation Error
content:
application/json:
schema:
title: HTTPValidationError
type: object
properties: &id001
detail:
title: Detail
type: array
items:
title: ValidationError
required:
- loc
- msg
- type
type: object
properties:
loc:
title: Location
type: array
items:
anyOf:
- type: string
- type: integer
msg:
title: Message
type: string
type:
title: Error Type
type: string
'403':
description: Authentication failed
/messageexchange/{mailbox_id}/inbox:
get:
tags:
- Inbox
summary: Check an inbox
description: |-
## Overview
Use this endpoint to return the message identifier of messages in the mailbox inbox ready for download.
Client systems MUST poll their assigned inbox a minimum of once a day and a maximum of once every five minutes for messages (unless there are more messages waiting to download).
A maximum of 500 message identifier are returned in every request. Continue the polling and download cycle until you empty the mailbox and you receive less than 500 messages in the response.
### Request
```shell
curl -k \
--request 'GET' \
--cacert 'mesh-ca.pem' \
--key 'mesh-client-key.pem' \
--cert 'mesh-client-cert.pem' \
--header 'accept: application/vnd.mesh.v2+json' \
--header 'authorization: NHSMESH X26HC005:66eef28b-e097-421d-998d-ea0c92c2c2fb:0:202006041718:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced' \
https://mesh-sync.spineservices.nhs.uk/messageexchange/X26HC005/inbox
```
### Response
for `accept: application/vnd.mesh.v2+json` and later if the inbox contains more than 500 messages, then 'links.next' will provide a way to page through all the messages in the inbox
```json
{
"messages": ["20220228174323222_ABCDEF", "20220228174323333_ABCDEF"],
"links": {
"self": "/messageexchange/mb12345/inbox?max_results=10",
"next": "/messageexchange/mb12345/inbox?max_results=10&continue_from=eyJwayI6ICJNQiNNU0cjTUIjMTIzNEhDMTIzNCMiLCAic2siOiAiTUIjTVNHIzIwMjIwMjI4MTc0MzIzMTIzX0FDREVEMSMifQ%3D%3D"
}
}
```
for `accept: application/vnd.mesh.v1+json` or `accept: application/json`
```json
{
"messages" : ["20200529155357895317_3573F8", "20220228174323333_ABCDEF"]
}
```
operationId: list_messages_messageexchange__mailbox_id__inbox_get
parameters:
- description: mailbox identifier
required: true
schema:
title: mailbox_id
minLength: 1
type: string
description: mailbox identifier
example: MAILBOX01
name: mailbox_id
in: path
- description: 'maximum results to return when using `accept: application/vnd.mesh.v2+json` if more results exist, `links.next` will be populated'
required: false
schema:
title: Max results
maximum: 5000.0
minimum: 10.0
type: integer
description: 'maximum results to return when using `accept: application/vnd.mesh.v2+json` if more results exist, `links.next` will be populated'
default: 500
example: '100'
name: max_results
in: query
- description: if more results exist than `max_results`, use `continue_from` to continue retrieving results from `links.next`
required: false
schema:
title: Continue From
maxLength: 1000
minLength: 24
type: string
description: if more results exist than `max_results`, use `continue_from` to continue retrieving results from `links.next`
examples:
'accept: application/vnd.mesh.v2+json':
value: eyJwayI6ICJNQiNNU0cjTUIjMTIzNEhDMTIzNCMiLCAic2siOiAiTUIjTVNHIzIwMjIwMjI4MTc0MzIzMTIzX0FDREVEMSMifQ%3D%3D
'accept: application/json':
value: 20220228174323123_ACDED1
name: continue_from
in: query
- description: |-
filter inbox by workflow id, conditions:
* equals: =WORKFLOW1
* does not equal: =!WORKFLOW1
* begins with: =WORKFL\*
* does not begin with: =!WORKFL\*
* contains: =\*_ACK\*
* does not contain: =!\*_ACK\*
required: false
schema:
title: Workflow Id filter
maxLength: 255
minLength: 2
type: string
description: |-
filter inbox by workflow id, conditions:
* equals: =WORKFLOW1
* does not equal: =!WORKFLOW1
* begins with: =WORKFL\*
* does not begin with: =!WORKFL\*
* contains: =\*_ACK\*
* does not contain: =!\*_ACK\*
example: '!*_ACK*'
name: workflow_filter
in: query
- description: Authorisation header
required: true
schema:
title: Authorization
type: string
description: Authorisation header
example: 'authorization: NHSMESH NONFUNC01:2c001608-5f09-4840-9611-bea43e666a30:1:201511201038:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced'
name: authorization
in: header
- description: the accepts header can be used to vary the response type
required: false
schema:
title: Accept
type: string
description: the accepts header can be used to vary the response type
default: application/json
example: application/vnd.mesh.v2+json
name: accept
in: header
responses:
'200':
description: Successful Response
content:
application/vnd.mesh.v2+json:
schema:
title: Inbox
required:
- messages
type: object
properties:
messages:
title: Messages
type: array
items:
type: string
description: list of message ids in the inbox, up to `max_results`
links:
title: Links
type: object
additionalProperties:
type: string
description: map of links, e.g. `links.next` if more results exist
approx_inbox_count:
title: Approx Inbox Count
type: integer
description: approximate inbox count, this is eventually consistent and should be used as an indication of inbox size only
example:
messages:
- 20220228174323222_ABCDEF
- 20220228174323333_ABCDEF
links:
self: /messageexchange/mb12345/inbox?max_results=10
next: /messageexchange/mb12345/inbox?max_results=10&continue_from=eyJwayI6ICJNQiNNU0cjTUIjMTIzNEhDMTIzNCMiLCAic2siOiAiTUIjTVNHIzIwMjIwMjI4MTc0MzIzMTIzX0FDREVEMSMifQ%3D%3D
approx_inbox_count: 100
application/json:
schema:
title: Inbox
required:
- messages
type: object
properties:
messages:
title: Messages
type: array
items:
type: string
description: list of message ids in the inbox, up to `max_results`
example:
messages:
- 20220228174323222_ABCDEF
- 20220228174323333_ABCDEF
'403':
description: Authentication failed
'400':
description: Validation Error
content:
application/json:
schema:
title: HTTPValidationError
type: object
properties: *id001
/messageexchange/{mailbox_id}/inbox/{message_id}:
get:
tags:
- Inbox
summary: Get Message
description: |-
## Overview
Use this endpoint to retrieve a message based on the message identifier obtained from the 'Check Inbox' endpoint.
**Note:** Headers should be treated case insensitively, most http clients will do this for you automatically, but please do not rely on explicit case.
### Message expiration
Messages you do not download and acknowledge within five days of delivery are removed from your inbox. The sending organisation receives an error report explaining that the receiver did not collect the message. Uncollected messages are completely deleted from the MESH server 30 days after initial delivery. If the sending organisation cannot re-send the message within the intervening time, they can contact the [NHS Digital national service desk](https://digital.nhs.uk/developer/help-and-support) with the error report details and ask for the message to be re-sent.
### Report Messages
The `Mex-MessageType` header indicates if the payload is a `DATA` message or a `REPORT`.
Error reports differ from regular messages in these ways:
- the Download message endpoint has a different value for the Mex-MessageType header
* DATA for a normal organisation-to-organisation message
* REPORT for an error report
- the Download message response body of an error report message is empty
### Request
```shell
curl -k \
--request 'GET' \
--cacert 'mesh-ca.pem' \
--key 'mesh-client-key.pem' \
--cert 'mesh-client-cert.pem' \
--header 'accept: application/vnd.mesh.v2+json' \
--header 'authorization: NHSMESH X26HC005:2942264f-46e5-450f-90fc-22a0c09efa37:0:202006041718:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced' \
https://msg.int.spine2.ncrs.nhs.uk/messageexchange/X26HC005/inbox/20200529155357895317_3573F8
```
### Response
```shell
HTTP/1.1 200 OK
content-type: application/octet-stream
content-length: 27
mex-content-compressed: N
mex-addresstype: ALL
mex-localid: api-docs-bob-sends-alice-a-chunked-file
mex-chunk-range: 2:2
etag: "866243ab74e0107a4d5835f8d6552e7f20c39ee1"
mex-filename: message.txt.gz
mex-version: 1.0
mex-workflowid: API-DOCS-TEST
mex-to: X26HC005
mex-messagetype: DATA
mex-messageid: 20200601122152994285_D59900
mex-from: X26HC006
m you in the future,
Bob.
```
operationId: retrieve_message_messageexchange__mailbox_id__inbox__message_id__get
parameters:
- description: mailbox identifier
required: true
schema:
title: mailbox_id
minLength: 1
type: string
description: mailbox identifier
example: MAILBOX01
name: mailbox_id
in: path
- description: message identifier
required: true
schema:
title: message_id
minLength: 1
type: string
description: message identifier
example: 20210311101813838554_1B8F53
name: message_id
in: path
- description: client accepted content encoding(s)
required: false
schema:
title: Accept-Encoding
type: string
description: client accepted content encoding(s)
default: ''
example: gzip
name: accept-encoding
in: header
- description: Authorisation header
required: true
schema:
title: Authorization
type: string
description: Authorisation header
example: 'authorization: NHSMESH NONFUNC01:2c001608-5f09-4840-9611-bea43e666a30:1:201511201038:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced'
name: authorization
in: header
responses:
'200':
description: OK, full message retrieved
content:
application/octet-stream:
schema:
format: binary
'403':
description: Authentication failed
'206':
description: Partial Content - Indicates that chunk has been downloaded successfully and that there are further chunks.
content:
application/octet-stream:
schema:
format: binary
'404':
description: Not Found, message does not exist
'410':
description: Gone, message has expired or otherwise failed
'400':
description: Validation Error
content:
application/json:
schema:
title: HTTPValidationError
type: object
properties: *id001
head:
tags:
- Inbox
summary: Head Message
description: |-
## Overview
Use this endpoint to retrieve a message metadata based on the `message_id` obtained from the 'Check Inbox' endpoint.
### Message expiration
Messages you do not download and acknowledge within five days of delivery are removed from your inbox. The sending organisation receives an error report explaining that the receiver did not collect the message. Uncollected messages are completely deleted from the MESH server 30 days after initial delivery. If the sending organisation cannot re-send the message within the intervening time, they can contact the [NHS Digital national service desk](https://digital.nhs.uk/developer/help-and-support) with the error report details and ask for the message to be re-sent.
### Report Messages
The `Mex-MessageType` header indicates if the payload is a `DATA` message or a `REPORT`.
Error reports differ from regular messages in these ways:
- the Download message endpoint has a different value for the `Mex-MessageType` header
* DATA for a normal organisation-to-organisation message
* REPORT for an error report
**Note:** Headers should be treated case insensitively, most http clients will do this for you automatically, but please do not rely on explicit case.
### Request
```shell
curl -k \
--request 'HEAD' \
--cacert 'mesh-ca.pem' \
--key 'mesh-client-key.pem' \
--cert 'mesh-client-cert.pem' \
--header 'accept: application/vnd.mesh.v2+json' \
--header 'authorization: NHSMESH X26HC005:2942264f-46e5-450f-90fc-22a0c09efa37:0:202006041718:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced' \
https://msg.int.spine2.ncrs.nhs.uk/messageexchange/{mailbox_id}/inbox/{message_id}
```
### Response
```shell
HTTP/1.1 200 OK
content-type: application/vnd.mesh.v2+json
content-length: 0
mex-content-compressed: N
mex-addresstype: ALL
mex-localid: api-docs-bob-sends-alice-a-chunked-file
mex-chunk-range: 2:2
etag: "866243ab74e0107a4d5835f8d6552e7f20c39ee1"
mex-filename: message.txt.gz
mex-version: 1.0
mex-workflowid: API-DOCS-TEST
mex-to: X26HC005
mex-messagetype: DATA
mex-messageid: 20200601122152994285_D59900
mex-from: X26HC006
```
operationId: head_message_messageexchange__mailbox_id__inbox__message_id__head
parameters:
- description: mailbox identifier
required: true
schema:
title: mailbox_id
minLength: 1
type: string
description: mailbox identifier
example: MAILBOX01
name: mailbox_id
in: path
- description: message identifier
required: true
schema:
title: message_id
minLength: 1
type: string
description: message identifier
example: 20210311101813838554_1B8F53
name: message_id
in: path
- description: Authorisation header
required: true
schema:
title: Authorization
type: string
description: Authorisation header
example: 'authorization: NHSMESH NONFUNC01:2c001608-5f09-4840-9611-bea43e666a30:1:201511201038:3cded68a9e0f9b83f2c5de1b79fc4dac45004523e6658d46145156fa6a03eced'
name: authorization
in: header
responses:
'200':
description: Successful Response
'403':
description: Authentication failed
'404':
description: Not Found, message does not exist
'410':
description: Gone, message has expired or otherwise failed