Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Liberty create integration essentials #60

Merged
merged 4 commits into from
Feb 13, 2024

Conversation

Adnan-cds
Copy link
Contributor

@Adnan-cds Adnan-cds commented Dec 16, 2023

New tokens and pseudo-tokens necessary for Liberty Create API integration:

  • [webform_submission:values:FORM-FIELD-ID:extracted_firstname]
  • [webform_submission:values:FORM-FIELD-ID:extracted_lastname]
  • [webform_submission:values:FORM-FIELD-ID:file_details_for_liberty_create_api]
  • [webform_submission:purge_date]

Also, a submodule with example form configuration demonstrating Liberty Create REST API integration. This is accompanied by a README that explains the integration.

Test failure under Drupal 10 appears unrelated to this pull request.

Closes #50

New tokens and pseudo-tokens:
- [webform_submission:values:FORM-FIELD-ID:extracted_firstname]
- [webform_submission:values:FORM-FIELD-ID:extracted_lastname]
- [webform_submission:values:FORM-FIELD-ID:file_details_for_liberty_create_api]
- [webform_submission:purge_date]
@Adnan-cds Adnan-cds changed the title Feature: Liberty create intergration essentials Feature: Liberty create integration essentials Dec 19, 2023
Submodule containing Liberty Create API integrated Webform.
These tokens are necessary for Liberty Create API integration.
@Adnan-cds Adnan-cds marked this pull request as ready for review December 22, 2023 18:53
@stephen-cox
Copy link
Member

@andybroomfield From Merge Tuesday - Will try and take a look at the tokens and README when he gets a chance

@stephen-cox
Copy link
Member

@stephen-cox Will have a look at the failing tests this week

@finnlewis
Copy link
Member

@andybroomfield could you take a closer look?

Lots of details in the README.md

@@ -0,0 +1,155 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be in the module root instead of localgov_forms_examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure Andy. The token from this file is not needed anywhere other than Liberty Create API integration. So I thought it better to just leave it in the demo submodule.

@andybroomfield
Copy link
Contributor

I'm seeing this on the example form once I first install, assume its because of the default settings from localgov_forms install (see #34).

Screenshot 2024-02-05 at 7 11 21 pm

Once I've got these installed, changing the example endpoint gives me this error

Completed custom data is using the following invalid tokens: [webform_submission:purge_date:custom:d/m/Y].

Its also not possible to save the handler as I get this error when trying to save it.

Custom options is using the following invalid tokens: [env:DRUPAL_LIBERTY_CREATE_API_AUTH_KEY], [env:DRUPAL_LIBERTY_CREATE_API_USERNAME], [env:DRUPAL_LIBERTY_CREATE_API_USER_KEY].

I've tried to set these up as envrionment options but still not getting a value.

@andybroomfield
Copy link
Contributor

Heres what the debug output

Debug: Remote post: Remote post [completed]
Submission state/operation: completed
Request URL https://example-build.oncreate.app/api/REST/case_to_crm/0.1
Request method POST
Request type json
Request options
headers:
  API-Authentication: '123456789'
  API-Username: test-user
  API-User-Token: qwertyuiopasdfghjklzxcvbnm
json:
  payload:
    client_unique_identifier: liberty_create_api_example/4
    function: case_to_crm_create_update_case
    data:
      -
        source_system: 'Drupal Webforms'
        source_ref: liberty_create_api_example/4
        date_time_created: '05/02/2024 19:59'
        resident_uprn: ''
        case_uprn: ''
        first_name: andy
        last_name: broo
        telephone_number_for_texts: '07123456789'
        email_address: test@example.com
        case_url: 'http://localgov.lndo.site:8080/webform/liberty_create_api_example/submissions/4?token=YCZcZ3WqJo88u0bp2hd9Wvyd5Y7PaBM2xDUBRS99OqU'
        nature_of_enquiry: 'Liberty Create API integration example'
        disposal_date: 06/03/2024
        details: |-
          Case address: ""
          Residential address: ""
          Details: "TEST"
        documents: {  }
Response status code: 403
Response header:
Server:
  - nginx
Date:
  - 'Mon, 05 Feb 2024 19:59:34 GMT'
Content-Type:
  - text/html
Content-Length:
  - '146'
Connection:
  - keep-alive
Response body:
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>
Response data:
"<html>\r\n<head><title>403 Forbidden</title></head>\r\n<body>\r\n<center><h1>403 Forbidden</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"
Response tokens:
Below tokens can ONLY be used to insert response data into value and hidden elements.
[webform:handler:remote_post:completed]
Message:
Client error: `POST https://example-build.oncreate.app/api/REST/case_to_crm/0.1` resulted in a `403 Forbidden` response:
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</c (truncated...)
Unable to process this submission. Please contact the site administrator.

@andybroomfield
Copy link
Contributor

Managed to get Lando to set the environment variables using a .env file (which if we want to do we will need to add to the lando / ddev project and add into .gitignore).
Testing with a post endpoint (since we don't have Liberty create). I see this.
Screenshot 2024-02-06 at 10 05 45 am

Headers

host: www.toptal.com
user-agent: Drupal/10.2.2 (+https://www.drupal.org/) GuzzleHttp/7
content-length: 2123
accept-encoding: gzip
api-authentication: 123456789
api-user-token: qwertyuiopasdfghjklzxcvbnm
api-username: test-user
cdn-loop: cloudflare, google
cf-connecting-ip: 82.8.230.143
cf-ipcountry: GB
cf-ray: 851292f6491652c9-LHR
cf-visitor: {"scheme":"https"}
content-type: application/json
x-cloud-trace-context: 7210bda81acaa91afc0be22ea0e7fe83/15771914655500934575
x-datadog-parent-id: 257490342694938105
x-datadog-sampling-priority: 0
x-datadog-trace-id: 7666191390181216861
x-forwarded-host: www.toptal.com
x-forwarded-server: inf-traefik-traefik-external-5c9d85bb6f-hh9sl
x-real-ip: 10.148.0.7

Body

payload: [object Object]
name: [object Object]
email: test@example.com
phone: 07123456789
details_of_enquiry: This is a test.
case_address: [object Object]
residential_address: [object Object]
api_response: [webform:handler:remote_post:completed:payload:result]; [webform:handler:remote_post:completed:payload:error_code]; [webform:handler:remote_post:completed:payload:error_desc]
api_result: [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]
case_ref: [webform:handler:remote_post:completed:payload:data:0:data:0:liberty_create_case_reference]
files:
more_files:
serial: 2
sid: 5
uuid: eb982561-59db-4774-bae0-a30b3a0520fa
token: KZ3rFKDuwB0LMKB480ljKYgmn9TT54VGOQmel80vGz0
uri: /form/liberty-create-api-example
created: 1707213918
completed: 1707213918
changed: 1707213918
in_draft: false
current_page:
remote_addr: 172.19.0.2
uid: 1
langcode: en
webform_id: liberty_create_api_example
entity_type:
entity_id:
locked: false
sticky: false
notes:

@Adnan-cds
Copy link
Contributor Author

Apart from the missing "Disposal date" sourced from the new [webform_submission:purge_date:custom:d/m/Y:clear] token, the rest of the output above looks good.

@Adnan-cds
Copy link
Contributor Author

Sorry Andy, I can't reproduce the error about the [webform_submission:purge_date:custom:d/m/Y:clear] token. I installed the localgov_forms_example_liberty_create_integration submodule on a fresh LocalGov Drupal site. Had to enable the Name, Email confirm, File, and Value Webform elements of course. Editing the "Remote post" handler of the Liberty Create API integration example Webform afterwards worked as usually.

@andybroomfield
Copy link
Contributor

Ok, I'm no longer getting that error, though still seeing name: [object Object] etc in Postbin, but I guess that is itself a postbin issue and not this module.

@Adnan-cds
Copy link
Contributor Author

Thanks a lot Andy. Merging...

@Adnan-cds Adnan-cds merged commit 8c8d5a6 into 1.x Feb 13, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Low-code platform integration
4 participants