Schedule icon
Request icon
Script icon
Process icon
If icon
Log icon
SlackIncomingWebhook icon

JSON API Response Validator

Validate configurable API JSON responses, branch on contract validity, and optionally notify Slack about failures.

Categories
CoreData

Validate an API response as part of a repeatable Kestra workflow. The blueprint calls a configurable URL, accepts unsuccessful HTTP responses as data for inspection, parses the response as JSON, and checks a small top-level contract. It then uses an If flow to handle valid and invalid responses and returns the validation result as a structured flow output.

How it works

  1. The scheduled_validation trigger is provided as a disabled hourly schedule. Enable it after configuring the target API.
  2. call_api uses io.kestra.plugin.core.http.Request to send a GET request to the api_url input. options.allowFailed: true keeps 4xx and 5xx responses available for validation rather than failing before the contract check.
  3. validate_response parses the response body and checks that the HTTP status equals expected_status_code, the body is a JSON object, and every field in required_fields exists.
  4. route_validation_result uses an If flow. Valid responses are logged as successful; invalid responses are logged with their validation errors and can optionally be sent to Slack.
  5. The validation_result output returns the status, validity flag, missing fields, and validation errors.

What you get

  • A configurable API URL and expected HTTP status.
  • Explicit handling of unsuccessful HTTP responses.
  • JSON parsing and required-field validation.
  • Separate valid and invalid response paths.
  • A structured validation_result output for downstream tasks.
  • Optional Slack notifications using a Kestra secret rather than a hardcoded credential.

Who it's for

  • QA engineers testing API contracts.
  • Platform and SRE teams building synthetic API checks.
  • Developers validating integrations before downstream processing.

Why orchestrate this with Kestra

A standalone script can make one request, but Kestra adds triggers, execution history, observable task boundaries, branching, secret management, and reusable outputs. The same validation can run manually, on a schedule, or as part of a larger data and integration workflow.

Prerequisites

  • A Kestra instance with the Core HTTP and Python Script plugins available.
  • Network access from the Kestra worker to the configured API URL.
  • A JSON API response matching the expected contract.

Secrets

  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL, required only when notify_slack is true. Do not put the webhook URL in this flow.

Expected response structure

With the default inputs, a valid response looks like:

{
  "id": 1,
  "title": "Example product",
  "price": 29.99
}

The response must be a JSON object with id, title, and price, and it must use HTTP status 200. Change required_fields and expected_status_code for another API contract.

Quick start

  1. Import this flow and execute it manually with the default inputs.
  2. Set api_url to the API endpoint you want to validate.
  3. Set required_fields to a JSON array of required top-level fields.
  4. Set notify_slack to true only after creating the SLACK_WEBHOOK_URL secret in Kestra.
  5. Review {{ outputs.validation_result }} and enable the schedule when the manual execution succeeds.

Validation conditions

A response is valid only when its HTTP status equals expected_status_code, its body parses as JSON, the parsed value is an object, and every name in required_fields is present. A 4xx/5xx status, malformed JSON, an array/scalar body, or a missing field produces an invalid result with a reason in errors.

Outputs

  • {{ outputs.validation_result }}: JSON object containing valid, http_status, expected_status, missing_fields, and errors.
  • {{ outputs.validate_response.vars.result }}: The same structured result available to downstream tasks in this flow.

How to extend

  • Add nested JSON-path checks for values such as status or data.items.
  • Add POST request inputs and a JSON request body for contract tests.
  • Add email, PagerDuty, or another notification plugin to the invalid branch.
  • Replace the hourly schedule with a webhook or upstream flow trigger.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.