Input Validation
You may remember that in the integration description we provided an example input that included a required email
field and optional limitQuery
and limitEmail
fields. If the requestor doesn't provide an email address in their input, how would we know where to send the digest? Or, what if the requestor provides invalid limit values (which should be positive integers)?
In this case we want the integration to fail gracefully and respond to the requestor with a failure status and indicate which field(s) need to be fixed. This is where Validation Rules (VRs) come in to play.
Adding Validation Rules to the integration
On the Build page, with Integration selected under Component at the top, right-click the row with
hackernews_email_digest
and select Go To > Validation Rule.Click the [➕ADD ROW] button 2 times to add 2 new rows. Enter the following values for each row:
First row:
Type:
INPUT
Field:
input.payload.email
Rule: (copy and paste the below Python code)
Second row:
Type:
INPUT
Field:
input.payload.limitQuery
Rule: (copy and paste the below Python code)
Select the second row and click the [DUPLICATE ROW] button at the bottom and make the following edits to the new row:
Field:
input.payload.limitEmail
Click the [💾 Save] button at the bottom.
If you are familiar with Python, you may have an idea of what is going on here.
(_
represents the value of the field named in the Field column)
In the first validation rule, we ensure that the provided email exists, is a string, and a properly formatted email using a regex expression.
In the second and third, we ensure that, the limits are either not provided or are positive integers
Testing the Validation Rules
Now we’re going to validate that our new Validation Rules work correctly.
Navigate to the Run History page. Select our most recent run, and click the curved arrow symbol on it. The Run Integration dialog window should appear.
Copy and paste this into the PAYLOAD:
Click RUN INTEGRATION at the bottom. It should run successfully.
On the Run History page, click the most recent integration and then the curved arrow again.
This time, provide some invalid values in our payload:
Re-run the integration again. It should fail.
Click the most recent run (once it appears- it may take a couple seconds). There should be two VALIDATION FAILURE records in the middle STEPS column. Clicking on them will provide information.
It's strongly encouraged to play around a little before continuing!
Try triggering the integration with various valid or invalid inputs.
Practice viewing them on the Run History page.
Last updated