Skip to content

Commit aea8b6d

Browse files
authored
Feat: Caselink 360 REST API integration. (#114)
Replacing the existing Liberty Create REST API integration example with a Liberty Create Caselink 360 REST API integration example.
1 parent 828efec commit aea8b6d

File tree

4 files changed

+82
-65
lines changed

4 files changed

+82
-65
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
},
1313
"require-dev": {
1414
"geocoder-php/nominatim-provider": "^5.2"
15+
},
16+
"suggest": {
17+
"drupal/token_environment": "^1.1.0"
1518
}
1619
}
Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
This module contains an example Webform configuration demonstrating integration with the Liberty Create Low-code API.
1+
This module contains an example Webform configuration demonstrating integration with a REST API created on the Netcall Liberty Create Low-code platform.
22

33
## Liberty Create API
4-
When we think of APIs, we usually think of it to have a fixed data structure. The Liberty Create API, however, does not refer to one or more APIs with fixed data structures. Instead, API designers can create necessary APIs from a drag-and-drop UI. This means, there is no common API spec that we can target for Drupal Webform integration.
4+
Liberty Create users can create custom APIs from a drag-and-drop UI. Due to the custom nature of these APIs, we cannot provide a single integration for Drupal Webforms. This means when faced with an integration task, Drupal site builders would have to study every such API method and come up with suitable Webform configurations.
55

6-
In the rest of this README, we describe an **example** Liberty Create API for CRM case creation and then explain how API integration is achieved with Drupal Webform.
6+
Caselink 360 is a CRM app created on the Liberty Create platform. It comes with a published API reference. This makes it possible for us to provide an example Webform integration with one of Caselink 360's REST API methods. This API method creates CRM case records.
7+
8+
The rest of this README explains the Webform configuration process with the hope that this explanation would be useful when integrating Drupal Webforms with other REST APIs built on the Liberty Create platform.
9+
10+
The example Webform provided in this module creates new CRM case records using the Caselink 360 app's `caselink_360_create_update_case` REST API method. First we take a look at a sample API request, then a sample API response, and finally explain the Webform configuration process.
711

812
## Example API request
9-
Let's look at an example REST API request first:
13+
Below we look at a REST API request to the `caselink_360_create_update_case` API method that creates a CRM case record:
14+
1015
```
1116
POST https://example-build.oncreate.app/api/REST/case_to_crm/0.1 HTTP/1.1
1217
API-Authentication: [Token hidden]
13-
API-Username: [Your username]
14-
API-User-Token: [Token hidden]
1518
Content-Type: application/json
1619
1720
{
1821
"payload":{
1922
"client_unique_identifier":"63105fe17248615689a02568ca95ff91",
20-
"function":"case_to_crm_create_update_case",
23+
"function":"caselink_360_create_update_case",
2124
"data":[
2225
{
2326
"source_system":"Some Text 1",
2427
"source_ref":"Some Text 2",
25-
"date_time_created":"25/12/2023 12:00",
28+
"nature_of_enquiry":"Some Text 5",
29+
"case_datetime_created":"25/12/2023 12:00",
2630
"resident_uprn":75,
2731
"case_uprn":75,
28-
"first_name":"Some Text 3",
29-
"last_name":"Some Text 4",
30-
"telephone_number_for_texts":"07700900000",
31-
"email_address":"[email protected]",
3232
"case_url":"http://www.example.com",
33-
"nature_of_enquiry":"Some Text 5",
3433
"disposal_date":"25/12/2023",
3534
"details":"Some Long Text 1",
35+
"first_name":"Some Text 3",
36+
"last_name":"Some Text 4",
37+
"date_of_birth":"25/12/2003",
38+
"email_address":"[email protected]",
39+
"phone_number":"07700900000",
3640
"documents":[
3741
{
3842
"file":{
@@ -51,7 +55,8 @@ Content-Type: application/json
5155
```
5256

5357
## Example API response
54-
What follows is an example response from the previous API call to create a CRM case.
58+
What follows is an example response from the previous API call to create a CRM case record:
59+
5560
```
5661
{
5762
"payload":{
@@ -69,94 +74,101 @@ What follows is an example response from the previous API call to create a CRM c
6974
"data":{
7075
"source_system":"Some Text 1",
7176
"source_ref":"Some Text 2",
72-
"date_time_created":"1703505600",
73-
"liberty_create_case_reference":"GE\/1"
77+
"case_datetime_created":"1703505600",
78+
"ch_case_ref":"GE\/1"
7479
}
7580
}
7681
]
7782
}
7883
}
7984
```
8085

81-
### Webform integration basics
82-
So this is how we setup the integration:
83-
- Under the "Settings > Emails/Handlers" tab of a Webform, add a "Remote post" Webform handler. This handler comes bundled with the Webform module.
84-
- Under the "General" tab of the handler configuration dialog, expand the "Completed" fieldset.
85-
- In the "Completed URL" field, enter the API endpoint URL. The example Webform config bundled with this module uses "https://example-build.oncreate.app/api/REST/case_to_crm/0.1" as this URL. Adjust it accordingly for your target endpoint.
86-
- In the "Completed custom data" field, map API fields with suitable Webform tokens. Refer to the example config below to get a better idea. This bit is in YAML format:
86+
## Webform integration basics
87+
This is how we setup API integration for the `caselink_360_create_update_case` API method:
88+
1. Under the "Settings > Emails/Handlers" tab of a Webform, add a "Remote post" Webform handler. This handler comes bundled with the Webform module. Note down the handler id which is usually autogenerated but can be edited manually if wished.
89+
2. Under the "General" tab of the handler configuration dialog, expand the "Completed" fieldset.
90+
3. In the "Completed URL" field, enter the API endpoint URL. The example Webform config bundled with this module uses "https://example-build.oncreate.app/api/REST/case_to_crm/0.1". Adjust it accordingly for your target endpoint.
91+
4. In the "Completed custom data" field, map API fields with suitable Webform tokens. Refer to the example config below to get a better idea. This bit is in YAML format:
8792
```
8893
payload:
89-
# client_unique_identifier is a required field.
94+
# client_unique_identifier is a required field. Its value should vary between requests.
9095
client_unique_identifier: "[webform:id]/[webform_submission:sid]"
9196
# "function" is also a required field.
92-
function: case_to_crm_create_update_case
97+
function: caselink_360_create_update_case
9398
# So is "data".
9499
data:
95100
-
96101
# source_system is a required field.
97102
source_system: "Drupal Webforms"
98103
# source_ref is a required field.
99104
source_ref: "[webform:id]/[webform_submission:sid]"
105+
# nature_of_enquiry is a required field.
106+
nature_of_enquiry: "[webform:title]"
100107
# Everything else below is optional.
101-
date_time_created: "[webform_submission:completed:custom:d/m/Y H:i]"
108+
case_datetime_created: "[webform_submission:completed:custom:d/m/Y H:i]"
102109
resident_uprn: "[webform_submission:values:residential_address:uprn]"
103110
case_uprn: "[webform_submission:values:case_address:uprn]"
104111
first_name: "[webform_submission:values:name:first]"
105112
last_name: "[webform_submission:values:name:last]"
106-
telephone_number_for_texts: "[webform_submission:values:phone]"
107-
email_address: "[webform_submission:values:email]"
113+
phone_number: "[webform_submission:values:phone]"
114+
email_address: "[webform_submission:values:email]"
115+
date_of_birth: "[webform_submission:values:date_of_birth:d/m/Y]"
108116
case_url: "[webform_submission:token-view-url]"
109-
nature_of_enquiry: "[webform:title]"
110117
disposal_date: "[webform_submission:purge_date:custom:d/m/Y:clear]"
111-
# For file fields, we use inline YAML syntax to avoid indentation issues. This is because "file_details_for_liberty_create_api", our custom file token, gets replaced with several *other* tokens before the token value insertion starts.
112-
documents: ["[webform_submission:values:files:file_details_for_liberty_create_api]", "[webform_submission:values:more_files:file_details_for_liberty_create_api]"]
113118
#
114119
# Any other Webform submission token should be placed within the "details" field below.
115120
details: |-
116121
Case address: "[webform_submission:values:case_address:clear]"
117122
Residential address: "[webform_submission:values:residential_address:clear]"
118123
Details: "[webform_submission:values:details_of_enquiry:clear]"
124+
# For file fields, we use inline YAML syntax to avoid indentation issues. This is because file_details_for_liberty_create_api, our custom file token, gets replaced with several *other* tokens before the token value insertion round starts.
125+
documents: ["[webform_submission:values:files:file_details_for_liberty_create_api]", "[webform_submission:values:more_files:file_details_for_liberty_create_api]"]
119126
```
127+
120128
This assumes our Webform carries at least the following fields:
121129
- name
130+
- date_of_birth
122131
- email
123132
- phone
124133
- residential_address
125134
- case_address
126135
- files
127136
- more_files
128-
- Uncheck everything under the "Submission data" fieldset.
129-
- Switch to the "Advanced" tab of the "Remote post" handler.
130-
- Under "Additional settings", select "POST" from the "Method" dropdown.
131-
- Select "JSON" from the "Post type" dropdown.
132-
- Try the following snippet for "Custom options":
137+
5. Uncheck everything under the "Submission data" fieldset.
138+
6. Switch to the "Advanced" tab of the "Remote post" handler.
139+
7. Under "Additional settings", select "POST" from the "Method" dropdown.
140+
8. Select "JSON" from the "Post type" dropdown.
141+
9. Insert the following snippet in "Custom options":
133142
```
134143
headers:
135144
API-Authentication: "[env:DRUPAL_LIBERTY_CREATE_API_AUTH_KEY]"
136-
API-Username: "[env:DRUPAL_LIBERTY_CREATE_API_USERNAME]"
137-
API-User-Token: "[env:DRUPAL_LIBERTY_CREATE_API_USER_KEY]"
138145
```
139-
This assumes that the [token_environment Drupal module](https://www.drupal.org/project/token_environment) is enabled and the following environment variables are present with their corresponding values:
140-
- DRUPAL_LIBERTY_CREATE_API_AUTH_KEY
141-
- DRUPAL_LIBERTY_CREATE_API_USERNAME
142-
- DRUPAL_LIBERTY_CREATE_API_USER_KEY
146+
This assumes that the [token_environment Drupal module](https://www.drupal.org/project/token_environment) is enabled and the DRUPAL_LIBERTY_CREATE_API_AUTH_KEY environment variable is present with its corresponding value.
147+
148+
Note that the token_environment module must be explicitly told that the DRUPAL_LIBERTY_CREATE_API_AUTH_KEY environment variable should be made available as a Drupal token. This is configured from "/admin/config/system/token-environment".
149+
150+
10. The [webform_queued_post_handler Drupal module](https://packagist.org/packages/cyberwoven/webform_queued_post_handler) provides an alternative to the "Remote post" handler. This handler is called "Async remote post" and uses Drupal's queue to manage API requests which is more reliable. Items in Drupal's queue are usually processed during cron runs. If you decide to use this handler instead, you may also find the [queue_ui](https://www.drupal.org/project/queue_ui) contrib module useful.
151+
152+
### Note
153+
If you install this module, almost all the above steps would be taken care of you except:
154+
- You would have to provide the right API endpoint URL referred to in step 3 above.
155+
- Make the API token value available as the DRUPAL_LIBERTY_CREATE_API_AUTH_KEY environment variable as mentioned in step 9.
143156

144-
Note that the token_environment module must be explicitly told that the above environment variables should be made available as Drupal tokens. This is configured from "/admin/config/system/token-environment".
145-
- The [webform_queued_post_handler Drupal module](https://packagist.org/packages/cyberwoven/webform_queued_post_handler) provides an alternate to the "Remote post" handler. This handler is called "Async remote post" and uses Drupal's queue to manage API requests. Items in Drupal's queue are usually processed during cron runs. If you decide to use this handler instead, you may also find the [queue_ui](https://www.drupal.org/project/queue_ui) contrib module useful.
157+
It is unlikely you would want to use the Caselink 360 integration Webform as is. Treat it more as an example to build up on rather than an end product.
146158

147159
## Inspecting API responses
148160
To inspect API responses, add the following "Value" type Webform elements to your Webform:
149-
- "crm_response" whose value should be `[webform:handler:async_remote_post:completed:payload:result]; [webform:handler:async_remote_post:completed:payload:error_code]; [webform:handler:async_remote_post:completed:payload:error_desc]`.
150-
- "crm_result" whose value should be `[webform:handler:async_remote_post:completed:payload:data:0:result]; [webform:handler:async_remote_post:completed:payload:data:0:error_code]; [webform:handler:async_remote_post:completed:payload:data:0:error_desc]`
151-
- "crm_case_ref" whose value should be `[webform:handler:async_remote_post:completed:payload:data:0:data:0:liberty_create_case_reference]`.
161+
- "crm_response" whose value should be `[webform:handler:remote_post:completed:payload:result]; [webform:handler:remote_post:completed:payload:error_code]; [webform:handler:remote_post:completed:payload:error_desc]`.
162+
- "crm_result" whose value should be `[webform:handler:remote_post:completed:payload:data:0:result]; [webform:handler:remote_post:completed:payload:data:0:error_code]; [webform:handler:remote_post:completed:payload:data:0:error_desc]`
163+
- "crm_case_ref" whose value should be `[webform:handler:remote_post:completed:payload:data:0:data:0:ch_case_ref]`.
152164

153165
This will ensure that API responses are stored alongside Webform submission values. This makes it easier to inspect these from the "Results" tab of Webforms.
154166

155-
As you can see, the three above field values are using multiple tokens and these tokens are referring to "async_remote_post" which is the handler id. Everything after ":completed:" in the token mirrors the API response. Change all these if necessary.
167+
As you can see, the three above field values are using multiple tokens and these tokens are referring to `remote_post` which is a handler id. This can vary dependencing on what handler id is in use. Everything after ":completed:" in the token mirrors the API response. Change all these if necessary.
156168

157169
## Summary
158-
- Liberty Create APIs will vary from organisation to organisation. There is no one-size fits all solution. You can study the example Webform config provided with this module to get an idea about the integration process.
159-
- Use the "Remote post" or "Async remote post" Webform handler to make HTTP POST requests to any Liberty Create REST API endpoint URLs.
170+
- Liberty Create APIs will vary from organisation to organisation. There is no one-size fits all solution. You can study the example Webform config provided with this module to get an idea about the integration process. This example creates CRM case records in the Caselink 360 Liberty Create app.
171+
- Use the "Remote post" or "Async remote post" Webform handler to make HTTP POST requests to any Liberty Create REST API endpoint URL.
160172
- Use the "Completed custom data" settings of the above handlers to map Webform fields to REST API fields.
161173
- Use the "Custom options" settings of the handlers to provide API authentication details.
162174
- Use the crm_response, crm_result, and crm_case_ref *Value* type Webform fields to capture API responses.

modules/localgov_forms_example_liberty_create_integration/config/optional/webform.webform.liberty_create_api_example.yml renamed to modules/localgov_forms_example_liberty_create_integration/config/optional/webform.webform.caselink_api_integration_example.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ dependencies: { }
44
weight: 0
55
open: null
66
close: null
7-
uid: 3
7+
uid: 1
88
template: false
99
archive: false
10-
id: liberty_create_api_example
11-
title: 'Liberty Create API integration example'
12-
description: ''
10+
id: caselink_api_integration_example
11+
title: 'Liberty Create Caselink 360 API integration example'
12+
description: '<p>Example Webform that passes form submission date to the Liberty Create "Caselink 360 - create / update case" API method.</p>'
1313
categories:
1414
- Example
1515
elements: |-
@@ -24,6 +24,9 @@ elements: |-
2424
'#last__required': true
2525
'#suffix__access': false
2626
'#degree__access': false
27+
date_of_birth:
28+
'#type': date
29+
'#title': 'Date of birth'
2730
email:
2831
'#type': webform_email_confirm
2932
'#title': Email
@@ -73,7 +76,7 @@ elements: |-
7376
case_ref:
7477
'#type': value
7578
'#title': 'CRM case reference'
76-
'#value': '[webform:handler:remote_post:completed:payload:data:0:data:0:liberty_create_case_reference]'
79+
'#value': '[webform:handler:remote_post:completed:payload:data:0:data:0:ch_case_ref]'
7780
files:
7881
'#type': managed_file
7982
'#title': Files
@@ -271,7 +274,7 @@ handlers:
271274
id: remote_post
272275
handler_id: remote_post
273276
label: 'Remote post'
274-
notes: 'Saves everything in a Queue. HTTP POST requests are later made by a queue worker.'
277+
notes: 'Makes HTTP POST requests to the given API endpoint.'
275278
status: true
276279
conditions: { }
277280
weight: 0
@@ -299,32 +302,32 @@ handlers:
299302
sticky: sticky
300303
notes: notes
301304
name: name
305+
date_of_birth: date_of_birth
302306
email: email
303307
phone: phone
304308
details_of_enquiry: details_of_enquiry
305-
residential_address: residential_address
306309
case_address: case_address
310+
residential_address: residential_address
307311
api_response: api_response
308312
api_result: api_result
309313
case_ref: case_ref
310314
files: files
311315
more_files: more_files
316+
date_of_birth_2: date_of_birth_2
312317
custom_data: ''
313318
custom_options: |-
314319
headers:
315320
API-Authentication: "[env:DRUPAL_LIBERTY_CREATE_API_AUTH_KEY]"
316-
API-Username: "[env:DRUPAL_LIBERTY_CREATE_API_USERNAME]"
317-
API-User-Token: "[env:DRUPAL_LIBERTY_CREATE_API_USER_KEY]"
318321
file_data: true
319322
cast: false
320323
debug: true
321-
completed_url: 'https://example-build.oncreate.app/api/REST/case_to_crm/0.1'
324+
completed_url: 'https://example-build.oncreate.app/api/REST/caselink360/1.0'
322325
completed_custom_data: |-
323326
payload:
324327
# client_unique_identifier is a required field.
325328
client_unique_identifier: "[webform:id]/[webform_submission:sid]"
326329
# "function" is also a required field.
327-
function: case_to_crm_create_update_case
330+
function: caselink_360_create_update_case
328331
# So is "data".
329332
data:
330333
-
@@ -333,13 +336,14 @@ handlers:
333336
# source_ref is a required field.
334337
source_ref: "[webform:id]/[webform_submission:sid]"
335338
# Everything else below is optional.
336-
date_time_created: "[webform_submission:completed:custom:d/m/Y H:i]"
339+
case_datetime_created: "[webform_submission:completed:custom:d/m/Y H:i]"
337340
resident_uprn: "[webform_submission:values:residential_address:uprn]"
338341
case_uprn: "[webform_submission:values:case_address:uprn]"
339342
first_name: "[webform_submission:values:name:first]"
340343
last_name: "[webform_submission:values:name:last]"
341-
telephone_number_for_texts: "[webform_submission:values:phone]"
342-
email_address: "[webform_submission:values:email]"
344+
phone_number: "[webform_submission:values:phone]"
345+
email_address: "[webform_submission:values:email]"
346+
date_of_birth: "[webform_submission:values:date_of_birth:d/m/Y]"
343347
case_url: "[webform_submission:token-view-url]"
344348
nature_of_enquiry: "[webform:title]"
345349
disposal_date: "[webform_submission:purge_date:custom:d/m/Y:clear]"

0 commit comments

Comments
 (0)