Post-request script
Introduction
Post-request scripts are useful for manipulating the response data before displaying or using it. You can extract specific values, format data, or even perform calculations. This helps in preparing the response data for further requests, or for displaying in a more user-friendly manner.
For example, we might have a connector which expects API requests to be authenticated with a {{token}}
value received in response to an authentication request. However, suppose that the authentication request response includes the required token value AND a client_id value in the same detail
field - somehow we need to ensure that only the token element is injected into a {{token}}
variable, to be used for authenticating subsequent API requests.
To achieve this, we could create a custom script to extract the the token element from the detail
field and then apply this to the post-request script tab for the required authentication method.
How it works
Let's use the example scenario above to break down how post-request scripts work:
A custom script should be created which extracts the token element of the
detail
field and applies this as the{{variable}}
value.This script is applied to the post-request script tab for the appropriate authentication method.
A user adds an instance using this authentication method, and enters their username and password.
The authentication request is sent and a successful response is returned, with client id and token values in the same
detail
field.The post-request script defined for this authentication method runs, extracting the token element from the
detail
field and injecting it into the{{token}}
variable for the authentication method.
Both pre and post request scripts have an expected format, where the input expects two different keys:
payload
- most commonly used, and contains the payload for the script.variables
- contains all authorisation variables, together with a hidden{{token}}
variable (which is created after the authentication request is sent).
Applying a post-request script
Any script that you want to apply must first be created as a custom script.
Step 1 Select the post-request script tab for your authentication method:
Step 2 Click in the select a script field and choose the script that you want to use - for example:
Step 3 Choose the script version that you want to use:
Step 4 Now you can review the script code to be applied and save changes:
If you need to change the script code, this should be done in the custom scripts area, then the updated script must be deployed.
Last updated