Example: create a condition

The example shows how to construct a condition request for the Response header Content-Type has a value that ends with json condition. To better understand the process, read descriptions of Conditions and Test catalog template in the Test Center concepts section.

To create a request that specifies the condition:

  1. Run the Get the test catalog template operation. The test catalog template's response object consists of the conditionNodes array and the triggerMappings object. This is a fragment of the conditionNodes array for the conditionId of 1.
{
  "conditionNodeId": 1,
  "conditionNodeDescription": "Root condition nodes",
  "valueControls": {
    "valueDataType": "string",
    "valueInputType": "single_choice",
    "newValueSupported": false,
    "availableValues": [
      "last_mile_acceleration",
      "ignore_case_in_cache_key",
      "origin_server_cache_key_hostname",
      "sure_route",
      "tiered_distribution",
      "response_code",
      "log_request_details",
      "caching_option",
      "variable",
      "cp_code",
      "redirect",
      "prefetch_objects",
      "response_header",
      "cache_key_query_parameters"
    ]
  }
}
  1. To create the condition, start from the conditionNodes array and conditionId of 1 of the test catalog template's response object. One of available values of the node is response_header, which is the first element of the condition. Enter the values into the request body.
{
  "condition": {
    "conditionNodeId": 1,
    "values": [
      "response_header"
    ]
  }
}
  1. In the test catalog template's response object, check what are the values you can use next for the selected value of the node. Go to the triggerMappings array and find the triggerValue for response_header. Check the conditionNodeId for conditionNode. This is the node triggered by the selection of response_header in the first node. In this case it's the node with conditionNodeId of 4.

  2. In the test catalog template's response object, go back to the conditionNodes array and conditionNodeId of 4. The description of the node states that it needs input from you. For this example it's Content-Type. Update the request body.

{
  "condition": {
    "conditionNodeId": 1,
    "values": [
      "response_header"
    ],
    "conditionNode": {
      "conditionNodeId": 4,
      "values": [
        "Content-Type"
      ]
    }
  }
}
  1. Go back to the test catalog template's response object and the triggerMappings array to check which node is triggered next. The consecutive conditionNodeId is 5.

  2. The description of the node in the conditionNodes array in the test catalog template's response object states that it requires a single selection out of the provided values. For this example it's has_a_value. Update the request body. Because the validPath for has_a_value is true you could finish the condition here, but then it would be just Response header Content-Type has a value.

{
  "condition": {
    "conditionNodeId": 1,
    "values": [
      "response_header"
    ],
    "conditionNode": {
      "conditionNodeId": 4,
      "values": [
        "Content-Type"
      ],
      "conditionNode": {
        "conditionNodeId": 5,
        "values": [
          "has_a_value"
        ]
      }
    }
  }
}
  1. Go back to the triggerMappings array of the test catalog template's response object and check which node was triggered next by the selected value. The consecutive conditionNodeId is 7. The description of the node in the conditionNodes array states that it requires a single selection out of the listed values. For this example it's ends_with. Update the request body.
{
  "condition": {
    "conditionNodeId": 1,
    "values": [
      "response_header"
    ],
    "conditionNode": {
      "conditionNodeId": 4,
      "values": [
        "Content-Type"
      ],
      "conditionNode": {
        "conditionNodeId": 5,
        "values": [
          "has_a_value"
        ],
        "conditionNode": {
          "conditionNodeId": 7,
          "values": [
            "ends_with"
          ]
        }
      }
    }
  }
}
  1. Go back to the triggerMappings array of the test catalog template's response object and check which node was triggered next. Because there were several values from which you could choose, you need to find triggerValue for ends_with and find triggered conditionNodeId. It's 4. This node was used before, so you known that it requires a single input from you. For this example it's json. Update the request body. The condition Response header Content-Type has a value that ends with json is ready. The validPath for the last node is true so the condition is finished. You can now use this as the POST request object when running the Create a condition operation.
{
  "condition": {
    "conditionNodeId": 1,
    "values": [
      "response_header"
    ],
    "conditionNode": {
      "conditionNodeId": 4,
      "values": [
        "Content-Type"
      ],
      "conditionNode": {
        "conditionNodeId": 5,
        "values": [
          "has_a_value"
        ],
        "conditionNode": {
          "conditionNodeId": 7,
          "values": [
            "ends_with"
          ],
          "conditionNode": {
            "conditionNodeId": 4,
            "values": [
              "json"
            ]
          }
        }
      }
    }
  }
}