Task - Execute script

This task allows you to run a script.

Execute Script

Description

Contains a description of the task, enter the reason for its existence here.

JSON key: description
Default value: Blank

Input

Enter the input to the script here - see Scripts and Macros for details on how to specify macro content.
The input is available to the script in the input variable.

JSON key: input
Default value: None

Script

Here, you can edit the script to be executed.

JSON key: script
Default: false

Example script:
// Input is set to the response contents
var json = JSON.parse(input);

json = json[0];

var result = {
    "name": json.name,
    "tld": json.topLevelDomain[0],
    "capital": json.capital,
    "headers": JSON.parse(state.requestAttributes.get("savedheaders"))
}

state.requestAttributes.put("result", JSON.stringify(result));

JSON Configuration

Below, is an example JSON configuration.

{
  "input": "%{compreq.response:lang_da}",
  "description": "Extract a few attributes from the response",
  "class": "io.ceptor.pipeline.tasks.ScriptRunnerTask",
  "script": "// Input is set to the response contents\nvar json = JSON.parse(input);\n\njson = json[0];\n\nvar result = {\n    \"name\": json.name,\n    \"tld\": json.topLevelDomain[0],\n    \"capital\": json.capital,\n    \"headers\": JSON.parse(state.requestAttributes.get(\"savedheaders\"))\n}\n\nstate.requestAttributes.put(\"result\", JSON.stringify(result));"
},


© Ceptor ApS. All Rights Reserved.