Skip to main content
This page explains how to retrieve data from two different services via API call and combine their outputs into a single output.

Scenario

  • Service1: Returns user information
  • Service2: Returns department information
  • Matching: When Service1.xDEPARTMANI == Service2.ChildDepartmentID, adds data from Service2 to Service1

Service1 Sample Output

Service2 Sample Output

Groovy Script

Explanation

This script performs the following operations:
  1. Retrieving Data from Service1: Retrieves user information from the first service with GET request.
  2. Retrieving Data from Service2: Retrieves department information from the second service with POST request.
  3. Matching: Uses linearFind function to find matching department information in Service2 for each record in Service1.
  4. Data Combining: When a match is found, adds ParentDepartmentID and ParentDepartmentName fields from Service2 to Service1 record.
  5. Returning Result: Returns combined data in JSON format.
This script should be run on the response line (Response Policy) because it uses the responseBodyTextToClient variable.