Skip to main content
This page explains how to make API calls in x-www-form-urlencoded format using Groovy script policy.

Groovy Script

Explanation

This script performs the following operations:
  1. Form Data Preparation: Prepares URL parameters in application/x-www-form-urlencoded format.
  2. HTTP Connection: Creates a connection for HTTP POST request.
  3. Content-Type Setting: Sets the application/x-www-form-urlencoded Content-Type.
  4. Data Sending: Sends form data as POST body.
  5. Response Processing: Processes and uses the response in JSON or text format.

Usage Scenario

This script can be used in operations such as obtaining OAuth tokens. Parameters are sent in form data format and the returned access token is added to the header.
This script should be run on the request line (Request Policy) because it uses the requestHeaderMapToTargetAPI variable.