Schedule icon
Script icon
Process icon
Write icon
If icon
SlackIncomingWebhook icon

API Contract Smoke Test with Slack Alerts

Test API endpoints for expected status and response markers, store JSON evidence, and alert Slack on contract failures.

Categories
CoreInfrastructure

Catch broken API deployments before consumers do. This blueprint runs a configurable list of HTTP checks, records the expected and actual status, measures latency, optionally verifies a marker in the response body, and writes the complete result to Kestra internal storage. A Slack message is sent only when a check fails.

Prerequisites

  • A Kestra instance with the Python Script and Slack plugins available.
  • Python 3 on the worker: the script runs with the Process task runner, not in a container.
  • Network access from the Kestra worker to each endpoint.
  • A secret named SLACK_WEBHOOK_URL holding the Slack incoming webhook that receives failure alerts. It is only read when notify_slack is true.
  • API_TOKEN and ORDERS_API_TOKEN in the examples below stand for the credentials of your own APIs; create whichever secrets your endpoints need.

Inputs

  • endpoints (JSON, required): the checks to run, described below.
  • user_agent (STRING, default kestra-api-contract-smoke-test): the User-Agent header sent with every request.
  • notify_slack (BOOL, default true): set to false to only store the report.

Endpoint input

endpoints is a JSON array. Each item supports:

  • name and url (required)
  • expected_status (integer, default 200; error statuses such as 404 are valid)
  • method (default GET)
  • headers (optional object; use {{ secret('API_TOKEN') }} for secrets)
  • body (optional JSON value for requests such as POST)
  • body_contains (optional text expected in the first 4 KB of the response)
  • timeout_seconds (optional positive number, default 10)

Example:

[
  {
    "name": "orders-readiness",
    "url": "https://api.example.com/ready",
    "expected_status": 200,
    "body_contains": "\"database\":\"ready\"",
    "headers": {
      "Authorization": "Bearer {{ secret('ORDERS_API_TOKEN') }}"
    }
  }
]

Quick start

  1. Set SLACK_WEBHOOK_URL if failure notifications are wanted.
  2. Replace the sample endpoint list with the APIs you own.
  3. Run the flow manually and inspect outputs.write_report.uri.
  4. Enable every_15_minutes after the checks pass.

The report output, {{ outputs.write_report.uri }}, points to a JSON document in Kestra internal storage. Each result includes actual_status, latency_ms, passed, and an assertion error when applicable. The failed_count output, {{ outputs.run_contract_checks.vars.failed_count }}, is the number of failed checks.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.