Pre-request script

Introduction

Pre-request scripts allow you to modify authentication request parameters before sending the actual request. You can set dynamic values, compute signatures, or add headers based on specific conditions.

For example, you may have a third-party application which only accepts user passwords which are base 64 encoded. Expecting your users to know how to encode their password when they need to add connector instance for this application isn't always realistic, so a pre-request script can take care of this automatically.

How it works

Let's use the example scenario above to break down how pre-request scripts work:

  1. A custom script should be created which takes a given password and performs base 64 encoding.

  2. This script is applied to the pre-request script tab for the appropriate authentication method.

  3. A user chooses to add an instance using this authentication method, and enters their username and password. Typically, an authentication request would be sent at this point - but NOT if a pre-request script is associated with the authentication method.

  4. The pre-request script defined for this authentication method runs - any required values from authentication variables provided by the user are taken to manipulate the authentication request body as needed.

  5. The authentication request is sent to to the given endpoint, including the manipulated body content.

  6. Once the script has run, the authentication request is made, including the encoded password.

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 pre-request script

Any script that you want to apply must first be created as a custom script.

Step 1 Select the pre-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