Skip to main content
This page explains a Groovy code example that dynamically converts a JSON content request to form data and makes an HTTP request.

Groovy Script

Explanation

This script performs the following operations:
  1. Parsing JSON: Parses the incoming JSON request body using JsonSlurper.
  2. Creating Form Data: Creates an entity in multipart/form-data format using MultipartEntityBuilder.
  3. Dynamic Field Addition: Adds each key-value pair in JSON to form data.
  4. Sending HTTP Request: Sends HTTP POST request with the created form data.
  5. Response Processing: Receives the result of the request and assigns it to necessary variables.

Usage Scenario

This script is used to convert a request in JSON format to form data format and send it to the backend service. It is particularly useful when the backend service expects data in form data format.
This script should be run on the request line (Request Policy) because it uses the requestBodyTextToTargetAPI variable.