notifications-ruby-client 6.0.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b04d33af2550021b9eecec2c063c360f349715c33353be054d9e2f7e4463896
4
- data.tar.gz: e4d0f5ece925c71a0ecfbc779bf27a94d29c8d7019b75b4b42955498ba58b2fe
3
+ metadata.gz: dcf0cee013cca39da0d0e3da3e7205ec6ab7d33dfea9c182b4aab80555b779a0
4
+ data.tar.gz: 1049787ca14191e6f944cc0029991f49b7d6af3525c998a8e7749b44d9c5f0ba
5
5
  SHA512:
6
- metadata.gz: 9158493f4a551508d9b4267fde147f345e0c0c47e5f46319bd92394b7a072d3b2c2543c9df841c0433685a86dd04eb1fb17fb5d6d18eede029ce11e6c798a65e
7
- data.tar.gz: be9ea47296e25def1236762ab0d3e00d6e72a2e0548b94aaa81cf2770e8d2ac976cfb5b6df8223a7f5db56e57de7f9375c84561b31e9b9af928f5554a97e5720
6
+ metadata.gz: a2098a9b4e86f186e46daa0e6f8ae20549aefbce3992c80724d15b1a7e58afa5ef0c73e4ef78f1a2840ac6dd5bde09d2e52cbfe5006492f5a595c57743028c9e
7
+ data.tar.gz: 9de9f0c4b8f41a3dc6b406da037f4b17a33bd3060c30eb991ea4c9013997af051117b6a924a2597d5aa6987b2e70a902c77d43c4f9ad13498a201395fef8ef5a
@@ -8,5 +8,7 @@
8
8
  <!--- All of the following are normally needed. Don’t worry if you haven’t done them or don’t know how – someone from the Notify team will be able to help. -->
9
9
  - [x] I’ve used the pull request template
10
10
  - [ ] I’ve written unit tests for these changes
11
- - [ ] I’ve updated the documentation (in `DOCUMENTATION.md`)
11
+ - [ ] I’ve updated the documentation in
12
+ - [ ] [notifications-tech-docs repository](https://github.com/alphagov/notifications-tech-docs/blob/main/source/documentation/client_docs/_ruby.md)
13
+ - [ ] `CHANGELOG.md`
12
14
  - [ ] I’ve bumped the version number (in `lib/notifications/client/version.rb`)
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 6.1.0
2
+
3
+ * Adds a `one_click_unsubscribe_url` parameter to `send_email` so services can allow users to easily unsubscribe from distribution lists.
4
+ * Adds a `one_click_unsubscribe_url` attribute to `Notification` class, so responses for get_notification include the unsubscribe link.
5
+
1
6
  ## 6.0.0
2
7
 
3
8
  * Removes the `is_csv` parameter from `prepare_upload`
data/bin/test_client.rb CHANGED
@@ -115,11 +115,14 @@ def test_template_preview(response)
115
115
  end
116
116
 
117
117
  def test_send_email_endpoint(client)
118
- email_resp = client.send_email(email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
119
- template_id: ENV['EMAIL_TEMPLATE_ID'],
120
- personalisation: { "name" => "some name" },
121
- reference: "some reference",
122
- email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
118
+ email_resp = client.send_email(
119
+ email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
120
+ template_id: ENV['EMAIL_TEMPLATE_ID'],
121
+ personalisation: { "name" => "some name" },
122
+ reference: "some reference",
123
+ email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
124
+ one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/unsubscribe?email_address=faye@example.com"
125
+ )
123
126
  test_notification_response_data_type(email_resp, 'email')
124
127
  email_resp
125
128
  end
@@ -130,7 +133,8 @@ def test_send_email_endpoint_with_document(client)
130
133
  template_id: ENV['EMAIL_TEMPLATE_ID'],
131
134
  personalisation: { name: Notifications.prepare_upload(f) },
132
135
  reference: "some reference",
133
- email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
136
+ email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
137
+ one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/unsubscribe?email_address=faye@example.com")
134
138
  end
135
139
 
136
140
  test_notification_response_data_type(email_resp, 'email')
@@ -319,7 +323,8 @@ end
319
323
  def expected_fields_in_email_content
320
324
  %w(from_email
321
325
  body
322
- subject)
326
+ subject
327
+ one_click_unsubscribe_url)
323
328
  end
324
329
 
325
330
  def expected_fields_in_sms_content
@@ -342,7 +347,8 @@ def expected_fields_in_email_notification
342
347
  template
343
348
  body
344
349
  subject
345
- created_at)
350
+ created_at
351
+ one_click_unsubscribe_url)
346
352
  end
347
353
 
348
354
  def expected_fields_in_email_notification_that_are_nil
@@ -381,7 +387,8 @@ def expected_fields_in_sms_notification_that_are_nil
381
387
  postcode
382
388
  subject
383
389
  created_by_name
384
- postage)
390
+ postage
391
+ one_click_unsubscribe_url)
385
392
  end
386
393
 
387
394
  def expected_fields_in_letter_notification
@@ -410,6 +417,7 @@ def expected_fields_in_letter_notification_that_are_nil
410
417
  line_5
411
418
  line_6
412
419
  created_by_name
420
+ one_click_unsubscribe_url
413
421
  )
414
422
  end
415
423
 
@@ -441,6 +449,7 @@ def expected_fields_in_precompiled_letter_notification_that_are_nil
441
449
  phone_number
442
450
  postcode
443
451
  sent_at
452
+ one_click_unsubscribe_url
444
453
  )
445
454
  end
446
455
 
@@ -25,6 +25,7 @@ module Notifications
25
25
  created_at
26
26
  completed_at
27
27
  created_by_name
28
+ one_click_unsubscribe_url
28
29
  ).freeze
29
30
 
30
31
  attr_reader(*FIELDS)
@@ -47,6 +47,8 @@ module Notifications
47
47
  # id of the email address that replies to email notifications will be sent to
48
48
  # @option form_data [String] :sms_sender_id
49
49
  # id of the sender to be used for an sms notification
50
+ # @option form_data [String] :one_click_unsubscribe_url
51
+ # link that end user can click to unsubscribe from the distribution list. We will pass this link in the email headers.
50
52
  # @see #perform_request!
51
53
  def post(kind, form_data)
52
54
  request = Net::HTTP::Post.new(
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "6.0.0".freeze
12
+ VERSION = "6.1.0".freeze
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-04 00:00:00.000000000 Z
11
+ date: 2024-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -120,7 +120,6 @@ files:
120
120
  - ".rubocop.yml"
121
121
  - CHANGELOG.md
122
122
  - CONTRIBUTING.md
123
- - DOCUMENTATION.md
124
123
  - Dockerfile
125
124
  - Gemfile
126
125
  - LICENSE
data/DOCUMENTATION.md DELETED
@@ -1,1126 +0,0 @@
1
- # Ruby client documentation
2
-
3
- This documentation is for developers interested in using the GOV.UK Notify Ruby client to send emails, text messages or letters.
4
-
5
- ## Set up the client
6
-
7
- ### Install the client
8
-
9
- Run the following in the command line:
10
-
11
- ```
12
- gem install 'notifications-ruby-client'
13
- ```
14
-
15
- Refer to the [client changelog](https://github.com/alphagov/notifications-ruby-client/blob/main/CHANGELOG.md) for the version number and the latest updates.
16
-
17
- ### Create a new instance of the client
18
-
19
- Add this code to your application:
20
-
21
- ```ruby
22
- require 'notifications/client'
23
- client = Notifications::Client.new(api_key)
24
- ```
25
-
26
- To get an API key, [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page. You can find more information in the [API keys](#api-keys) section of this documentation.
27
-
28
- ## Send a message
29
-
30
- You can use GOV.UK Notify to send text messages, emails or letters.
31
-
32
- ### Send a text message
33
-
34
- #### Method
35
-
36
- ```ruby
37
- smsresponse = client.send_sms(
38
- phone_number: "+447900900123",
39
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
40
- )
41
- ```
42
-
43
- #### Arguments
44
-
45
- ##### phone_number (required)
46
-
47
- The phone number of the text message recipient. This can be a UK or international number. For example:
48
-
49
- ```ruby
50
- phone_number:"+447900900123"
51
- ```
52
-
53
- ##### template_id (required)
54
-
55
- To find the template ID:
56
-
57
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
58
- 1. Go to the __Templates__ page and select the relevant template.
59
- 1. Select __Copy template ID to clipboard__.
60
-
61
- For example:
62
-
63
- ```ruby
64
- template_id:"f33517ff-2a88-4f6e-b855-c550268ce08a"
65
- ```
66
-
67
- ##### personalisation (optional)
68
-
69
- If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
70
-
71
- ```ruby
72
- personalisation: {
73
- name: "John Smith",
74
- ID: "300241",
75
- }
76
- ```
77
-
78
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
79
-
80
- ##### reference (optional)
81
-
82
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
83
-
84
- ```ruby
85
- reference: "your_reference_string"
86
- ```
87
-
88
- You can leave out this argument if you do not have a reference.
89
-
90
- ##### sms_sender_id (optional)
91
-
92
- A unique identifier of the sender of the text message notification.
93
-
94
- To find the text message sender:
95
-
96
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
97
- 1. Go to the __Settings__ page.
98
- 1. In the __Text Messages__ section, select __Manage__ on the __Text Message sender__ row.
99
-
100
- You can then either:
101
-
102
- - copy the sender ID that you want to use and paste it into the method
103
- - select __Change__ to change the default sender that the service uses, and select __Save__
104
-
105
-
106
- For example:
107
-
108
- ```ruby
109
- sms_sender_id: "8e222534-7f05-4972-86e3-17c5d9f894e2"
110
- ```
111
-
112
- You can leave out this argument if your service only has one text message sender, or if you want to use the default sender.
113
-
114
- #### Response
115
-
116
- If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#method), the object is named `smsresponse`.
117
-
118
- You can then call different methods on this object:
119
-
120
- |Method|Information|Type|
121
- |:---|:---|:---|
122
- |#`smsresponse.id`|Notification UUID|String|
123
- |#`smsresponse.reference`|`reference` argument|String|
124
- |#`smsresponse.content`|- `body`: Message body sent to the recipient<br>- `from_number`: SMS sender number of your service|Hash|
125
- |#`smsresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
126
- |#`smsresponse.uri`|Notification URL|String|
127
-
128
- If you are using the [test API key](#test), all your messages come back with a `delivered` status.
129
-
130
- All messages sent using the [team and guest list](#team-and-guest-list) or [live](#live) keys appear on your GOV.UK Notify dashboard.
131
-
132
- #### Error codes
133
-
134
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
135
-
136
- |error.code|error.message|class|How to fix|
137
- |:---|:---|:---|:---|
138
- |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
139
- |`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
140
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
141
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
142
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information|
143
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`ClientError`|Refer to [service limits](#daily-limits) for the limit number|
144
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
145
-
146
- ### Send an email
147
-
148
- #### Method
149
-
150
- ```ruby
151
- emailresponse = client.send_email(
152
- email_address: "sender@something.com",
153
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
154
- )
155
- ```
156
-
157
- #### Arguments
158
-
159
- ##### email_address (required)
160
-
161
- The email address of the recipient. For example:
162
-
163
- ```ruby
164
- email_address: "sender@something.com"
165
- ```
166
-
167
- ##### template_id (required)
168
-
169
- To find the template ID:
170
-
171
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
172
- 1. Go to the __Templates__ page and select the relevant template.
173
- 1. Select __Copy template ID to clipboard__.
174
-
175
- For example:
176
-
177
- ```ruby
178
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
179
- ```
180
-
181
- ##### personalisation (optional)
182
-
183
- If a template has placeholder fields for personalised information such as name or reference number, you must provide their values in a hash. For example:
184
-
185
- ```ruby
186
- personalisation: {
187
- name: "John Smith",
188
- year: "2016",
189
- # pass in an array and it will appear as bullet points in the message:
190
- required_documents: ["passport", "utility bill", "other id"],
191
- }
192
- ```
193
-
194
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
195
-
196
- ##### reference (optional)
197
-
198
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
199
-
200
- ```ruby
201
- reference: "your_reference_string"
202
- ```
203
-
204
- You can leave out this argument if you do not have a reference.
205
-
206
- ##### email_reply_to_id (optional)
207
-
208
- This is an email address specified by you to receive replies from your users. You must add at least one reply-to email address before your service can go live.
209
-
210
- To add a reply-to email address:
211
-
212
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
213
- 1. Go to the __Settings__ page.
214
- 1. In the __Email__ section, select __Manage__ on the __Reply-to email addresses__ row.
215
- 1. Select __Add reply-to address__.
216
- 1. Enter the email address you want to use, and select __Add__.
217
-
218
- For example:
219
-
220
- ```ruby
221
- email_reply_to_id: '8e222534-7f05-4972-86e3-17c5d9f894e2'
222
- ```
223
-
224
- You can leave out this argument if your service only has one email reply-to address, or you want to use the default email address.
225
-
226
- ### Send a file by email
227
-
228
- To send a file by email, add a placeholder to the template then upload a file. The placeholder will contain a secure link to download the file.
229
-
230
- The links are unique and unguessable. GOV.UK Notify cannot access or decrypt your file.
231
-
232
- Your file will be available to download for a default period of 26 weeks (6 months).
233
-
234
- To help protect your files you can also:
235
-
236
- * ask recipients to confirm their email address before downloading
237
- * choose the length of time that a file is available to download
238
-
239
- #### Add contact details to the file download page
240
-
241
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
242
- 1. Go to the __Settings__ page.
243
- 1. In the __Email__ section, select __Manage__ on the __Send files by email__ row.
244
- 1. Enter the contact details you want to use, and select __Save__.
245
-
246
- #### Add a placeholder to the template
247
-
248
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
249
- 1. Go to the __Templates__ page and select the relevant email template.
250
- 1. Select __Edit__.
251
- 1. Add a placeholder to the email template using double brackets. For example: "Download your file at: ((link_to_file))"
252
-
253
- Your email should also tell recipients how long the file will be available to download.
254
-
255
- #### Upload your file
256
-
257
- You can upload PDF, CSV, JSON, .odt, .txt, .rtf, .xlsx and MS Word Document files. Your file must be smaller than 2MB. [Contact the GOV.UK Notify team](https://www.notifications.service.gov.uk/support/ask-question-give-feedback) if you need to send other file types.
258
-
259
- 1. Pass the file object as an argument to the `Notifications.prepare_upload` helper method.
260
- 1. Pass the result into the personalisation argument.
261
-
262
- For example:
263
-
264
- ```ruby
265
- File.open("file.pdf", "rb") do |f|
266
- ...
267
- personalisation: {
268
- first_name: "Amala",
269
- application_date: "2018-01-01",
270
- link_to_file: Notifications.prepare_upload(f),
271
- }
272
- end
273
- ```
274
-
275
- #### Set the filename
276
-
277
- To do this you will need version 6.0.0 of the Ruby client library, or a more recent version.
278
-
279
- You should provide a filename when you upload your file.
280
-
281
- The filename should tell the recipient what the file contains. A memorable filename can help the recipient to find the file again later.
282
-
283
- The filename must end with a file extension. For example, `.csv` for a CSV file. If you include the wrong file extension, recipients may not be able to open your file.
284
-
285
- If you do not provide a filename for your file, Notify will:
286
-
287
- * generate a random filename
288
- * try to add the correct file extension
289
-
290
- If Notify cannot add the correct file extension, recipients may not be able to open your file.
291
-
292
- ```ruby
293
- File.open("file.csv", "rb") do |f|
294
- ...
295
- personalisation: {
296
- first_name: "Amala",
297
- application_date: "2018-01-01",
298
- link_to_file: Notifications.prepare_upload(f, filename="2023-12-25-daily-report.csv"),
299
- }
300
- end
301
- ```
302
-
303
- #### Ask recipients to confirm their email address before they can download the file
304
-
305
- When a recipient clicks the link in the email you’ve sent them, they have to enter their email address. Only someone who knows the recipient’s email address can download the file.
306
-
307
- This security feature is turned on by default.
308
-
309
- ##### Turn off email address check (not recommended)
310
-
311
- If you do not want to use this feature, you can turn it off on a file-by-file basis.
312
-
313
- To do this you will need version 5.4.0 of the Ruby client library, or a more recent version.
314
-
315
- You should not turn this feature off if you send files that contain:
316
-
317
- * personally identifiable information
318
- * commercially sensitive information
319
- * information classified as ‘OFFICIAL’ or ‘OFFICIAL-SENSITIVE’ under the [Government Security Classifications](https://www.gov.uk/government/publications/government-security-classifications) policy
320
-
321
- To let the recipient download the file without confirming their email address, set the `confirm_email_before_download` flag to `false`.
322
-
323
-
324
-
325
- ```ruby
326
- File.open("file.pdf", "rb") do |f|
327
- ...
328
- personalisation: {
329
- first_name: "Amala",
330
- application_date: "2018-01-01",
331
- link_to_file: Notifications.prepare_upload(f, confirm_email_before_download: false),
332
- }
333
- end
334
- ```
335
-
336
- #### Choose the length of time that a file is available to download
337
-
338
- Set the number of weeks you want the file to be available using the `retention_period` key.
339
-
340
- To use this feature will need version 5.4.0 of the Ruby client library, or a more recent version.
341
-
342
- You can choose any value between 1 week and 78 weeks. When deciding this, you should consider:
343
-
344
- * the need to protect the recipient’s personal information
345
- * whether the recipient will need to download the file again later
346
-
347
- If you do not choose a value, the file will be available for the default period of 26 weeks (6 months).
348
-
349
- Files sent before 12 April 2023 had a longer default period of 78 weeks (18 months).
350
-
351
- ```ruby
352
- File.open("file.pdf", "rb") do |f|
353
- ...
354
- personalisation: {
355
- first_name: "Amala",
356
- application_date: "2018-01-01",
357
- link_to_file: Notifications.prepare_upload(f, retention_period: '52 weeks'),
358
- }
359
- end
360
- ```
361
-
362
- #### Response
363
-
364
- If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#send-an-email-method), the object is named `emailresponse`.
365
-
366
- You can then call different methods on this object to return the requested information.
367
-
368
- |Method|Information|Type|
369
- |:---|:---|:---|
370
- |#`emailresponse.id`|Notification UUID|String|
371
- |#`emailresponse.reference`|`reference` argument|String|
372
- |#`emailresponse.content`|- `body`: Message body<br>- `subject`: Message subject<br>- `from_email`: From email address of your service found on the **Settings** page|Hash|
373
- |#`emailresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
374
- |#`emailresponse.uri`|Notification URL|String|
375
-
376
- #### Error codes
377
-
378
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
379
-
380
- |error.code|error.message|class|How to fix|
381
- |:--- |:---|:---|:---|
382
- |`400`|`BadRequestError: Can't send to this recipient using a team-only API key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
383
- |`400`|`BadRequestError: Can't send to this recipient when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
384
- |`400`|`BadRequestError: Unsupported file type '(FILE TYPE)'. Supported types are: '(ALLOWED TYPES)'`|`BadRequestError`|Wrong file type. You can only upload .pdf, .csv, .txt, .doc, .docx, .xlsx, .rtf or .odt files|
385
- |`400`|`BadRequestError: Unsupported value for retention_period '(PERIOD)'. Supported periods are from 1 to 78 weeks.`|`BadRequestError`|Choose a period between 1 and 78 weeks|
386
- |`400`|`BadRequestError: Unsupported value for confirm_email_before_download: '(VALUE)'. Use a boolean true or false value.`|`BadRequestError`|Use either true or false|
387
- |`400`|`BadRequestError: File did not pass the virus scan`|`BadRequestError`|The file contains a virus|
388
- |`400`|`BadRequestError: Send files by email has not been set up - add contact details for your service at https://www.notifications.service.gov.uk/services/(SERVICE ID)/service-settings/send-files-by-email`|`BadRequestError`|See how to [add contact details to the file download page](#add-contact-details-to-the-file-download-page)|
389
- |`400`|`BadRequestError: Can only send a file by email` | `BadRequestError`|Make sure you are using an email template|
390
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
391
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
392
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information|
393
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number|
394
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification|
395
- |-|`ArgumentError: File is larger than 2MB")`|-|The file is too big. Files must be smaller than 2MB|
396
-
397
- ### Send a letter
398
-
399
- When you add a new service it will start in [trial mode](https://www.notifications.service.gov.uk/features/trial-mode). You can only send letters when your service is live.
400
-
401
- To send Notify a request to go live:
402
-
403
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
404
- 1. Go to the __Settings__ page.
405
- 1. In the __Your service is in trial mode__ section, select __request to go live__.
406
-
407
- #### Method
408
-
409
- ```ruby
410
- letterresponse = client.send_letter(
411
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a",
412
- personalisation: {
413
- address_line_1: 'The Occupier',
414
- address_line_2: '123 High Street',
415
- address_line_3: 'SW14 6BH',
416
- },
417
- )
418
- ```
419
-
420
- #### Arguments
421
-
422
- ##### template_id (required)
423
-
424
- To find the template ID:
425
-
426
- 1. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in).
427
- 1. Go to the __Templates__ page and select the relevant template.
428
- 1. Select __Copy template ID to clipboard__.
429
-
430
- For example:
431
-
432
- ```ruby
433
- template_id: "f33517ff-2a88-4f6e-b855-c550268ce08a"
434
- ```
435
-
436
- ##### personalisation (required)
437
-
438
- The personalisation argument always contains the following parameters for the letter recipient’s address:
439
-
440
- - `address_line_1`
441
- - `address_line_2`
442
- - `address_line_3`
443
- - `address_line_4`
444
- - `address_line_5`
445
- - `address_line_6`
446
- - `address_line_7`
447
-
448
- The address must have at least 3 lines.
449
-
450
- The last line needs to be a real UK postcode or the name of a country outside the UK.
451
-
452
- Notify checks for international addresses and will automatically charge you the correct postage.
453
-
454
- The `postcode` personalisation argument has been replaced. If your template still uses `postcode`, Notify will treat it as the last line of the address.
455
-
456
- Any other placeholder fields included in the letter template also count as required parameters. You must provide their values in a hash. For example:
457
-
458
-
459
- ```ruby
460
- personalisation: {
461
- address_line_1: 'The Occupier', # mandatory address field
462
- address_line_2: '123 High Street', # mandatory address field
463
- address_line_3: 'SW14 6BH', # mandatory address field
464
- name: 'John Smith', # field from template
465
- application_date: '2018-01-01' # field from template,
466
- # pass in an array and it will appear as bullet points in the letter:
467
- required_documents: ["passport", "utility bill", "other id"],
468
- },
469
- ```
470
-
471
- ##### reference (optional)
472
-
473
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
474
-
475
- ```ruby
476
- reference: 'your_reference_string'
477
- ```
478
-
479
- #### Response
480
-
481
- If the request to the client is successful, the client returns a `Notifications::Client:ResponseNotification` object. In the example shown in the [Method section](#send-a-letter-method), the object is named `letterresponse`.
482
-
483
- You can then call different methods on this object to return the requested information.
484
-
485
- |Method|Information|Type|
486
- |:---|:---|:---|
487
- |#`letterresponse.id`|Notification UUID|String|
488
- |#`letterresponse.reference`|`reference` argument|String|
489
- |#`letterresponse.content`|- `body`: Letter body<br>- `subject`: Letter subject or main heading|Hash|
490
- |#`letterresponse.template`|Contains the `id`, `version` and `uri` of the template|Hash|
491
- |#`letterresponse.uri`|Notification URL|String|
492
-
493
-
494
- #### Error codes
495
-
496
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
497
-
498
- |error.code|error.message|class|How to fix|
499
- |:--- |:---|:---|:---|
500
- |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys).|
501
- |`400`|`BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode).|
502
- |`400`|`ValidationError: personalisation address_line_1 is a required property`|`BadRequestError`|Ensure that your template has a field for the first line of the address, refer to [personalisation](#personalisation-required) for more information.|
503
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Must be a real UK postcode"`<br>`}]`|Ensure that the value for the last line of the address is a real UK postcode.|
504
- |`400`|`[{`<br>`"error": "ValidationError",`<br>`"message": "Last line of address must be a real UK postcode or another country"`<br>`}]`|Ensure that the value for the last line of the address is a real UK postcode or the name of a country outside the UK.|
505
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock.|
506
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information.|
507
- |`429`|`RateLimitError: Exceeded rate limit for key type TEAM/TEST/LIVE of 3000 requests per 60 seconds`|`RateLimitError`|Refer to [API rate limits](#rate-limits) for more information.|
508
- |`429`|`TooManyRequestsError: Exceeded send limits (LIMIT NUMBER) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number.|
509
- |`500`|`Exception: Internal server error`|`ServerError`|Notify was unable to process the request, resend your notification.|
510
-
511
- ### Send a precompiled letter
512
-
513
- #### Method
514
- ```ruby
515
- precompiled_letter = client.send_precompiled_letter(reference, pdf_file)
516
- ```
517
-
518
- #### Arguments
519
-
520
- ##### reference (required)
521
- A unique identifier you create. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address.
522
-
523
- ##### pdf_file (required)
524
-
525
- The precompiled letter must be a PDF file which meets [the GOV.UK Notify letter specification](https://www.notifications.service.gov.uk/using-notify/guidance/letter-specification).
526
-
527
- ```ruby
528
- File.open("path/to/pdf_file", "rb") do |pdf_file|
529
- client.send_precompiled_letter("your reference", pdf_file)
530
- end
531
- ```
532
-
533
- ##### postage (optional)
534
-
535
- You can choose first or second class postage for your precompiled letter. Set the value to `first` for first class, or `second` for second class. If you do not pass in this argument, the postage will default to second class.
536
-
537
-
538
- #### Response
539
-
540
- If the request to the client is successful, the client returns a `Notifications::Client:ResponsePrecompiledLetter` object. In the example shown in the [Method section](#send-a-precompiled-letter-method), the object is named `precompiled_letter`.
541
-
542
- You can then call different methods on this object to return the requested information.
543
-
544
- |Method|Information|Type|
545
- |:---|:---|:---|
546
- |#`precompiled_letter.id`|Notification UUID|String|
547
- |#`precompiled_letter.reference`|`reference` argument|String|
548
- |#`precompiled_letter.postage`|`postage` argument|String|
549
-
550
-
551
- #### Error codes
552
-
553
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
554
-
555
- |error.status_code|error.message|class|How to fix|
556
- |:---|:---|:---|:---|
557
- |`400`|`BadRequestError: Cannot send letters with a team api key`|`BadRequestError`|Use the correct type of [API key](#api-keys)|
558
- |`400`|`BadRequestError: Letter content is not a valid PDF`|`BadRequestError`|PDF file format is required|
559
- |`400`|`BadRequestError: Cannot send letters when service is in trial mode - see https://www.notifications.service.gov.uk/trial-mode`|`BadRequestError`|Your service cannot send this notification in [trial mode](https://www.notifications.service.gov.uk/features/using-notify#trial-mode)|
560
- |`400`|`ValidationError: reference is a required property`|`BadRequestError`|Add a `reference` argument to the method call|
561
- |`400`|`ValidationError: postage invalid. It must be either first or second.`|`BadRequestError`|Change the value of `postage` argument in the method call to either 'first' or 'second'|
562
- |`429`|`RateLimitError: Exceeded rate limit for key type live of 10 requests per 20 seconds`|`RateLimitError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
563
- |`429`|`TooManyRequestsError: Exceeded send limits (50) for today`|`RateLimitError`|Refer to [service limits](#daily-limits) for the limit number|
564
-
565
- ## Get message status
566
-
567
-
568
-
569
- ### Get the status of one message
570
-
571
- You can only get the status of messages sent within the retention period. The default retention period is 7 days.
572
-
573
- #### Method
574
-
575
- ```ruby
576
- response = client.get_notification(id)
577
- ```
578
-
579
- #### Arguments
580
-
581
- ##### id (required)
582
-
583
- The ID of the notification. To find the notification ID, you can either:
584
-
585
- * check the response to the [original notification method call](#response)
586
- * [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page
587
-
588
- #### Response
589
-
590
- If the request to the client is successful, the client returns a `Notifications::Client::Notification` object. In the example shown in the [Method section](#get-the-status-of-one-message-method), the object is named `response`.
591
-
592
- You can then call different methods on this object to return the requested information.
593
-
594
- |Method|Information|Type|
595
- |:---|:---|:---|
596
- |#`response.id`|Notification UUID|String|
597
- |#`response.reference`| String supplied in `reference` argument|String|
598
- |#`response.email_address`|Recipient email address (email only)|String|
599
- |#`response.phone_number`|Recipient phone number (SMS only)|String|
600
- |#`response.line_1`|Recipient address line 1 of the address (letter only)|String|
601
- |#`response.line_2`|Recipient address line 2 of the address (letter only)|String|
602
- |#`response.line_3`|Recipient address line 3 of the address (letter only)|String|
603
- |#`response.line_4`|Recipient address line 4 of the address (letter only)|String|
604
- |#`response.line_5`|Recipient address line 5 of the address (letter only)|String|
605
- |#`response.line_6`|Recipient address line 6 of the address (letter only)|String|
606
- |#`response.line_7`|Recipient address line 7 of the address (letter only)|String|
607
- |#`response.postage`|Postage class of the notification sent (letter only)|String|
608
- |#`response.type`|Type of notification sent (sms, email or letter)|String|
609
- |#`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
610
- |#`response.template`|Template UUID|String|
611
- |#`response.body`|Notification body|String|
612
- |#`response.subject`|Notification subject (email and letter)|String|
613
- |#`response.sent_at`|Date and time notification sent to provider|String|
614
- |#`response.created_at`|Date and time notification created|String|
615
- |#`response.completed_at`|Date and time notification delivered or failed|String|
616
- |#`response.created_by_name`|Name of sender if notification sent manually|String|
617
-
618
- #### Error codes
619
-
620
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
621
-
622
- |error.code|error.message|class|How to fix|
623
- |:---|:---|:---|:---|
624
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
625
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
626
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
627
- |`404`|`NoResultFound: No result found`|`NotFoundError`|Check the notification ID. This error occurs if the notification is more than 7 days old.|
628
-
629
- ### Get the status of multiple messages
630
-
631
- This API call returns one page of up to 250 messages and statuses. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
632
-
633
- You can only get messages that are 7 days old or newer.
634
-
635
- #### Method
636
-
637
- ```ruby
638
- args = {
639
- template_type: 'sms',
640
- status: 'failed',
641
- reference: 'your_reference_string'
642
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
643
- }
644
- response = client.get_notifications(args)
645
- ```
646
-
647
- You can leave out the `older_than` argument to get the 250 most recent messages.
648
-
649
- To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next 250 oldest messages from the specified notification ID.
650
-
651
- #### Arguments
652
-
653
- You can leave out these arguments to ignore these filters.
654
-
655
- ##### status (optional)
656
-
657
- You can filter by each:
658
-
659
- * [email status](#email-status-descriptions)
660
- * [text message status](#text-message-status-descriptions)
661
- * [letter status](#letter-status-descriptions)
662
- * [precompiled letter status](#precompiled-letter-status-descriptions)
663
-
664
- You can leave out this argument to ignore this filter.
665
-
666
- ##### templateType (optional)
667
-
668
- You can filter by:
669
-
670
- * `email`
671
- * `sms`
672
- * `letter`
673
-
674
- ##### reference (optional)
675
-
676
- A unique identifier you can create if necessary. This reference identifies a single unique notification or a batch of notifications. It must not contain any personal information such as name or postal address. For example:
677
-
678
- ```ruby
679
- reference: 'your_reference_string'
680
- ```
681
-
682
- ##### older_than (optional)
683
-
684
- Input the ID of a notification into this argument. If you use this argument, the client returns the next 250 received notifications older than the given ID. For example:
685
-
686
- ```ruby
687
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
688
- ```
689
-
690
- If you leave out this argument, the client returns the most recent 250 notifications.
691
-
692
- The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty response.
693
-
694
- #### Response
695
-
696
- If the request to the client is successful, the client returns a `Notifications::Client::NotificationsCollection` object. In the example shown in the [Method section](#get-the-status-of-multiple-messages-method), the object is named `response`.
697
-
698
- You must then call either the `.links` method or the `.collection` method on this object.
699
-
700
- |Method|Information|
701
- |:---|:---|
702
- |#`response.links`|Returns a hash linking to the requested notifications (limited to 250)|
703
- |#`response.collection`|Returns an array of the required notifications|
704
-
705
- If you call the `collection` method on this object to return a notification array, you must then call the following methods on the notifications in this array to return information on those notifications:
706
-
707
- |Method|Information|Type|
708
- |:---|:---|:---|
709
- |#`response.id`|Notification UUID|String|
710
- |#`response.reference`| String supplied in `reference` argument|String|
711
- |#`response.email_address`|Recipient email address (email only)|String|
712
- |#`response.phone_number`|Recipient phone number (SMS only)|String|
713
- |#`response.line_1`|Recipient address line 1 of the address (letter only)|String|
714
- |#`response.line_2`|Recipient address line 2 of the address (letter only)|String|
715
- |#`response.line_3`|Recipient address line 3 of the address (letter only)|String|
716
- |#`response.line_4`|Recipient address line 4 of the address (letter only)|String|
717
- |#`response.line_5`|Recipient address line 5 of the address (letter only)|String|
718
- |#`response.line_6`|Recipient address line 6 of the address (letter only)|String|
719
- |#`response.postcode`|Recipient postcode (letter only)|String|
720
- |#`response.type`|Type of notification sent (sms, email or letter)|String|
721
- |#`response.status`|Notification status (sending / delivered / permanent-failure / temporary-failure / technical-failure)|String|
722
- |#`response.template`|Template UUID|String|
723
- |#`response.body`|Notification body|String|
724
- |#`response.subject`|Notification subject (email and letter)|String|
725
- |#`response.sent_at`|Date and time notification sent to provider|String|
726
- |#`response.created_at`|Date and time notification created|String|
727
- |#`response.completed_at`|Date and time notification delivered or failed|String|
728
- |#`response.created_by_name`|Name of sender if notification sent manually|String|
729
-
730
- If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
731
-
732
- #### Error codes
733
-
734
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
735
-
736
- |error.code|error.message|class|How to fix|
737
- |:---|:---|:---|:---|
738
- |`400`|`ValidationError: bad status is not one of [created, sending, sent, delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted, received]`|`BadRequestError`|Contact the GOV.UK Notify team|
739
- |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the GOV.UK Notify team|
740
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
741
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
742
-
743
- ### Email status descriptions
744
-
745
- |Status|Description|
746
- |:---|:---|
747
- |#`created`|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|
748
- |#`sending`|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information.|
749
- |#`delivered`|The message was successfully delivered.|
750
- |#`permanent-failure`|The provider could not deliver the message because the email address was wrong. You should remove these email addresses from your database.|
751
- |#`temporary-failure`|The provider could not deliver the message. This can happen when the recipient’s inbox is full or their anti-spam filter rejects your email. [Check your content does not look like spam](https://www.gov.uk/service-manual/design/sending-emails-and-text-messages#protect-your-users-from-spam-and-phishing) before you try to send the message again.|
752
- |#`technical-failure`|Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again.|
753
-
754
- ### Text message status descriptions
755
-
756
- |Status|Description|
757
- |:---|:---|
758
- |#`created`|GOV.UK Notify has placed the message in a queue, ready to be sent to the provider. It should only remain in this state for a few seconds.|
759
- |#`sending`|GOV.UK Notify has sent the message to the provider. The provider will try to deliver the message to the recipient for up to 72 hours. GOV.UK Notify is waiting for delivery information.|
760
- |#`pending`|GOV.UK Notify is waiting for more delivery information.<br>GOV.UK Notify received a callback from the provider but the recipient’s device has not yet responded. Another callback from the provider determines the final status of the text message.|
761
- |#`sent`|The message was sent to an international number. The mobile networks in some countries do not provide any more delivery information. The GOV.UK Notify website displays this status as 'Sent to an international number'.|
762
- |#`delivered`|The message was successfully delivered. If a recipient blocks your sender name or mobile number, your message will still show as delivered.|
763
- |#`permanent-failure`|The provider could not deliver the message. This can happen if the phone number was wrong or if the network operator rejects the message. If you’re sure that these phone numbers are correct, you should [contact GOV.UK Notify support](https://www.notifications.service.gov.uk/support). If not, you should remove them from your database. You’ll still be charged for text messages that cannot be delivered.
764
- |#`temporary-failure`|The provider could not deliver the message. This can happen when the recipient’s phone is off, has no signal, or their text message inbox is full. You can try to send the message again. You’ll still be charged for text messages to phones that are not accepting messages.|
765
- |#`technical-failure`|Your message was not sent because there was a problem between Notify and the provider.<br>You’ll have to try sending your messages again. You will not be charged for text messages that are affected by a technical failure.|
766
-
767
- ### Letter status descriptions
768
-
769
- |Status|Description|
770
- |:---|:---|
771
- |#`accepted`|GOV.UK Notify has sent the letter to the provider to be printed.|
772
- |#`received`|The provider has printed and dispatched the letter.|
773
- |#`cancelled`|Sending cancelled. The letter will not be printed or dispatched.|
774
- |#`technical-failure`|GOV.UK Notify had an unexpected error while sending the letter to our printing provider.|
775
- |#`permanent-failure`|The provider cannot print the letter. Your letter will not be dispatched.|
776
-
777
- ### Precompiled letter status descriptions
778
-
779
- |Status|Description|
780
- |:---|:---|
781
- |#`accepted`|GOV.UK Notify has sent the letter to the provider to be printed.|
782
- |#`received`|The provider has printed and dispatched the letter.|
783
- |#`cancelled`|Sending cancelled. The letter will not be printed or dispatched.|
784
- |#`pending-virus-check`|GOV.UK Notify has not completed a virus scan of the precompiled letter file.|
785
- |#`virus-scan-failed`|GOV.UK Notify found a potential virus in the precompiled letter file.|
786
- |#`validation-failed`|Content in the precompiled letter file is outside the printable area. See the [GOV.UK Notify letter specification](https://www.notifications.service.gov.uk/using-notify/guidance/letter-specification) for more information.|
787
- |#`technical-failure`|GOV.UK Notify had an unexpected error while sending the letter to our printing provider.|
788
- |#`permanent-failure`|The provider cannot print the letter. Your letter will not be dispatched.|
789
-
790
-
791
- ### Get a PDF for a letter notification
792
-
793
- #### Method
794
-
795
- This returns the pdf contents of a letter notification.
796
-
797
- ```ruby
798
- pdf_file = client.get_pdf_for_letter(
799
- 'f33517ff-2a88-4f6e-b855-c550268ce08a' # notification id (required)
800
- )
801
- ```
802
-
803
- #### Arguments
804
-
805
- ##### id (required)
806
-
807
- The ID of the notification. To find the notification ID, you can either:
808
-
809
- * check the response to the [original notification method call](#get-the-status-of-one-message-response)
810
- * [sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __API integration__ page
811
-
812
- #### Response
813
-
814
- If the request to the client is successful, the client will return a `string` containing the raw PDF data.
815
-
816
- #### Error codes
817
-
818
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
819
-
820
- |error.code|error.message|class|How to fix|
821
- |:---|:---|:---|:---|
822
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
823
- |`400`|`PDFNotReadyError: PDF not available yet, try again later`|`BadRequestError`|Wait for the notification to finish processing. This usually takes a few seconds|
824
- |`400`|`BadRequestError: File did not pass the virus scan`|`BadRequestError`|You cannot retrieve the contents of a letter notification that contains a virus|
825
- |`400`|`BadRequestError: PDF not available for letters in technical-failure`|`BadRequestError`|You cannot retrieve the contents of a letter notification in technical-failure|
826
- |`400`|`ValidationError: Notification is not a letter`|`BadRequestError`|Check that you are looking up the correct notification|
827
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`BadRequestError`|Check your system clock|
828
- |`403`|`AuthError: Invalid token: API key not found`|`BadRequestError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
829
- |`404`|`NoResultFound: No result found`|`BadRequestError`|Check the notification ID|
830
-
831
-
832
- ## Get a template
833
-
834
- ### Get a template by ID
835
-
836
- #### Method
837
-
838
- This returns the latest version of the template.
839
-
840
- ```ruby
841
- response = client.get_template_by_id(id)
842
- ```
843
-
844
- #### Arguments
845
-
846
- ##### id (required)
847
-
848
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
849
-
850
- ```
851
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
852
- ```
853
-
854
- #### Response
855
-
856
- If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](#get-a-template-by-id-method), the object is named `response`.
857
-
858
- You can then call different methods on this object to return the requested information.
859
-
860
- |Method|Information|Type|
861
- |:---|:---|:---|
862
- |#`response.id`|Template UUID|String|
863
- |#`response.name`|Template name|String|
864
- |#`response.type`|Template type (email/sms/letter)|String|
865
- |#`response.created_at`|Date and time template created|String|
866
- |#`response.updated_at`|Date and time template last updated (may be nil if version 1)|String|
867
- |#`response.created_by`|Email address of person that created the template|String|
868
- |#`response.version`|Template version|String|
869
- |#`response.body`|Template content|String|
870
- |#`response.subject`|Template subject (email and letter)|String|
871
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
872
-
873
- #### Error codes
874
-
875
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
876
-
877
- |error.code|error.message|class|How to fix|
878
- |:---|:---|:---|:---|
879
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
880
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
881
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
882
- |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-arguments-id-required)|
883
-
884
- ### Get a template by ID and version
885
-
886
- #### Method
887
-
888
- ```ruby
889
- response = client.get_template_version(id, version)
890
- ```
891
-
892
- #### Arguments
893
-
894
- ##### id (required)
895
-
896
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
897
-
898
- ```ruby
899
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
900
- ```
901
-
902
- ##### version (required)
903
-
904
- The version number of the template.
905
-
906
- #### Response
907
-
908
- If the request to the client is successful, the client returns a `Notifications::Client::Template` object. In the example shown in the [Method section](#get-a-template-by-id-and-version-method), the object is named `response`.
909
-
910
- You can then call different methods on this object to return the requested information.
911
-
912
- |Method|Information|Type|
913
- |:---|:---|:---|
914
- |#`response.id`|Template UUID|String|
915
- |#`response.name`|Template name|String|
916
- |#`response.type`|Template type (email/sms/letter)|String|
917
- |#`response.created_at`|Date and time template created|String|
918
- |#`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
919
- |#`response.created_by`|Email address of person that created the template|String|
920
- |#`response.version`|Template version|String|
921
- |#`response.body`|Template content|String|
922
- |#`response.subject`|Template subject (email and letter)|String|
923
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
924
-
925
- #### Error codes
926
-
927
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
928
-
929
- |error.code|error.message|class|How to fix|
930
- |:---|:---|:---|:---|
931
- |`400`|`ValidationError: id is not a valid UUID`|`BadRequestError`|Check the notification ID|
932
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
933
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
934
- |`404`|`NoResultFound: No Result Found`|`NotFoundError`|Check your [template ID](#get-a-template-by-id-and-version-arguments-id-required) and [version](#version-required)|
935
-
936
- ### Get all templates
937
-
938
- #### Method
939
-
940
- This returns the latest version of all templates inside a collection object.
941
-
942
- ```ruby
943
- args = {
944
- type: 'sms'
945
- }
946
- response = client.get_all_templates(args)
947
- ```
948
-
949
- #### Arguments
950
-
951
- ##### type (optional)
952
-
953
- If you do not use `type`, the client returns all templates. Otherwise you can filter by:
954
-
955
- - `email`
956
- - `sms`
957
- - `letter`
958
-
959
- #### Response
960
-
961
- If the request to the client is successful, the client returns a `Notifications::Client::TemplateCollection` object. In the example shown in the [Method section](#get-all-templates-method), the object is named `response`.
962
-
963
- You must then call the `.collection` method on this object to return an array of the required templates.
964
-
965
- Once the client has returned a template array, you must then call the following methods on the templates in this array to return information on those templates.
966
-
967
- |Method|Information|Type|
968
- |:---|:---|:---|
969
- |#`response.id`|Template UUID|String|
970
- |#`response.name`|Template name|String|
971
- |#`response.type`|Template type (email/sms/letter)|String|
972
- |#`response.created_at`|Date and time template created|String|
973
- |#`response.updated_at`|Date and time template last updated (may be nil if it is the first version)|String|
974
- |#`response.created_by`|Email address of person that created the template|String|
975
- |#`response.version`|Template version|String|
976
- |#`response.body`|Template content|String|
977
- |#`response.subject`|Template subject (email and letter)|String|
978
- |#`response.letter_contact_block`|Template letter contact block (letter)|String|
979
-
980
- If no templates exist for a template type or there no templates for a service, the templates array will be empty.
981
-
982
- #### Error codes
983
-
984
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
985
-
986
- |error.code|error.message|class|How to fix|
987
- |:---|:---|:---|:---|
988
- |`400`|`ValidationError: Template type is not one of [sms, email, letter]`|`BadRequestError`|Contact the Notify team|
989
-
990
- ### Generate a preview template
991
-
992
- #### Method
993
-
994
- This generates a preview version of a template.
995
-
996
- ```ruby
997
- response = client.generate_template_preview(id)
998
- ```
999
-
1000
- The parameters in the personalisation argument must match the placeholder fields in the actual template. The API notification client ignores any extra fields in the method.
1001
-
1002
- #### Arguments
1003
-
1004
- ##### id (required)
1005
-
1006
- The ID of the template. [Sign in to GOV.UK Notify](https://www.notifications.service.gov.uk/sign-in) and go to the __Templates__ page to find it. For example:
1007
-
1008
- ```ruby
1009
- 'f33517ff-2a88-4f6e-b855-c550268ce08a'
1010
- ```
1011
-
1012
- ##### personalisation (optional)
1013
-
1014
- If a template has placeholder fields for personalised information such as name or application date, you must provide their values in a hash. For example:
1015
-
1016
- ```ruby
1017
- personalisation: {
1018
- name: "John Smith",
1019
- ID: "300241",
1020
- }
1021
- ```
1022
-
1023
- You can leave out this argument if a template does not have any placeholder fields for personalised information.
1024
-
1025
- #### Response
1026
-
1027
- If the request to the client is successful, the client returns a `Notifications::Client::TemplatePreview` object. In the example shown in the [Method section](#generate-a-preview-template-method), the object is named `response`.
1028
-
1029
- You can then call different methods on this object to return the requested information.
1030
-
1031
- |Method|Information|Type|
1032
- |:---|:---|:---|
1033
- |#`response.id`|Template UUID|String|
1034
- |#`response.version`|Template version|String|
1035
- |#`response.body`|Template content|String|
1036
- |#`response.subject`|Template subject (email and letter)|String|
1037
- |#`response.type`|Template type (sms/email/letter)|String|
1038
- |#`response.html`|Body as rendered HTML (email only)|String|
1039
-
1040
- #### Error codes
1041
-
1042
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
1043
-
1044
- |error.code|error.message|class|How to fix|
1045
- |:---|:---|:---|:---|
1046
- |`400`|`BadRequestError: Missing personalisation: [PERSONALISATION FIELD]`|`BadRequestError`|Check that the personalisation arguments in the method match the placeholder fields in the template|
1047
- |`400`|`NoResultFound: No result found`|`BadRequestError`|Check the [template ID](#generate-a-preview-template-arguments-id-required)|
1048
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
1049
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|
1050
-
1051
- ## Get received text messages
1052
-
1053
- This API call returns one page of up to 250 received text messages. You can get either the most recent messages, or get older messages by specifying a particular notification ID in the `older_than` argument.
1054
-
1055
- You can only get the status of messages that are 7 days old or newer.
1056
-
1057
- You can also set up [callbacks](#callbacks) for received text messages.
1058
-
1059
- ### Enable received text messages
1060
-
1061
- To receive text messages:
1062
-
1063
- 1. Go to the **Text message settings** section of the **Settings** page.
1064
- 1. Select **Change** on the **Receive text messages** row.
1065
-
1066
- ### Get a page of received text messages
1067
-
1068
- #### Method
1069
-
1070
- ```ruby
1071
- args = {
1072
- older_than: 'e194efd1-c34d-49c9-9915-e4267e01e92e'
1073
- }
1074
- response = client.get_received_texts(args)
1075
- ```
1076
-
1077
- To get older messages, pass the ID of an older notification into the `older_than` argument. This returns the next oldest messages from the specified notification ID.
1078
-
1079
- If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
1080
-
1081
- #### Arguments
1082
-
1083
- ##### older_than (optional)
1084
-
1085
- Input the ID of a received text message into this argument. If you use this argument, the client returns the next 250 received text messages older than the given ID. For example:
1086
-
1087
- ```ruby
1088
- older_than: '8e222534-7f05-4972-86e3-17c5d9f894e2'
1089
- ```
1090
-
1091
- If you leave out the `older_than` argument, the client returns the most recent 250 notifications.
1092
-
1093
- The client only returns notifications that are 7 days old or newer. If the notification specified in this argument is older than 7 days, the client returns an empty `collection` response.
1094
-
1095
- #### Response
1096
-
1097
- If the request to the client is successful, the client returns a `Notifications::Client::ReceivedTextCollection` object. In the example shown in the [Method section](#get-a-page-of-received-text-messages-method), the object is named `response`.
1098
-
1099
- You must then call either the `.links` method or the `.collection` method on this object.
1100
-
1101
- |Method|Information|
1102
- |:---|:---|
1103
- |#`response.links`|Returns a hash linking to the requested texts (limited to 250)|
1104
- |#`response.collection`|Returns an array of the required texts|
1105
-
1106
- If you call the `collection` method on this object to return an array, you must then call the following methods on the received texts in this array to return information on those texts:
1107
-
1108
- |Method|Information|Type|
1109
- |:---|:---|:---|
1110
- |#`response.id`|Received text UUID|String|
1111
- |#`response.created_at`|Date and time of received text|String|
1112
- |#`response.content`|Received text content|String|
1113
- |#`response.notify_number`|Number that received text was sent to|String|
1114
- |#`response.service_id`|Received text service ID|String|
1115
- |#`response.user_number`|Number that received text was sent from|String|
1116
-
1117
- If the notification specified in the `older_than` argument is older than 7 days, the client returns an empty `collection` response.
1118
-
1119
- #### Error codes
1120
-
1121
- If the request is not successful, the client raises a `Notifications::Client::RequestError` exception (or a subclass), which contains a code:
1122
-
1123
- |error.code|error.message|class|How to fix|
1124
- |:---|:---|:---|:---|
1125
- |`403`|`AuthError: Error: Your system clock must be accurate to within 30 seconds`|`AuthError`|Check your system clock|
1126
- |`403`|`AuthError: Invalid token: API key not found`|`AuthError`|Use the correct API key. Refer to [API keys](#api-keys) for more information|