Map the API response fields

Before you begin

The following tasks must be completed:
  1. Starting the z/OS Connect Designer with Docker and importing an OpenAPI definition.
  2. Configuring your connections to Db2.
  3. Create the getEmployees z/OS Asset.
  4. Map the API request to the z/OS Asset.
  5. Define GET /employees responses.

About this task

This topic is applicable to: z/OS Connect Designer
capability Content applicable to
application developers

The responses from the z/OS Asset must be mapped to the fields of the API response. In the task, Define GET /employees responses you defined the order in which the response codes are checked. You now map the data that is returned for each API response.

Procedure

  1. Open the Operation flow diagram as described Mapping your API and z/OS Assets.
    The Operation flow diagram shows the responses that need to be mapped. An amber exclamation mark icon An amber exclamation mark indicates that the mapping is not defined.

    The GET/employees operation can return either a 200 or 500 response code. In the following steps, you configure each one of these responses to return the data that you want.
  2. Click 200 on the Operation flow diagram.

    A 200 response indicates that the requested employee records were found and the information is returned in an array. This data array must be mapped to the fields of the API response.

    Figure 1. 200 response node.
    200 response node.
  3. Map the returned ResultSet Output array.

    The body of the 200 response is an array of the returned employees. You pass in a returned array structure from the getEmployees z/OS Asset.

    Within the For each mapping input, do one of the following actions
    • Select the ResultSet Output node from the Input selection window.
    • Enter the following directly into the field.
      $zosAssetResponse.body."ResultSet Output"
    Figure 2. Mapping in the returned array.
    Mapping in the returned array.
    Figure 3. The mapped array.
    The mapped array.

    This configuration iterates over the returned ResultSet Output array that contains the list of employees and maps the fields for each employee within the array.

  4. Map API Response bio field.

    For each employee, add a small bio. This bio is a concatenation of their given and family names.

    1. Select the FIRSTNME input.

      Notice when selecting from the Input selection window that it suggests a selection from ResultSet Row item / Object. This is focusing the selection for that array member.

      Figure 4. Selecting the 'FIRSTNME' input.
      Selecting the 'FIRSTNME' input.
    2. Enter the syntax to concatenate the FIRSTNME and LASTNAME inputs.

      In the bio field after the already selected FIRSTNME, add a space then start typing lastname and select LASTNAME from the menu.

      Figure 5. Concatenating fields.
      Concatenating fields.
    3. Continue typing to build the sentence FIRSTNAME LASTNAME works in WORKDEPT.
      As you type, Designer continually searches for matching field names.
      Figure 6. Completed mapping.
      Completed mapping.
  5. Map remaining the API response fields

    In the same way as previous steps, you can choose to map the corresponding fields between the z/OS Asset and the API response.

    Figure 7. Completed 200 response.
    Completed 200 response.
  6. Click 500 on the Operation flow diagram.
    A 500 response indicates an internal server error. Configure the 500 response to return the error code and the contents of the StatusDescription field by typing the following into the message field:
    {{$error.message}}{{$zosAssetResponse.body.StatusDescription}}
    Alternatively, you can click Insert a mapping icon and select those fields from the menu.
    Figure 8. Mapping for a 500 response.
    Mapping for a 500 response

Results

You successfully mapped the response codes for the GET/employees operation.

What to do next

Test the GET /employees operation