{
  "workflow_id": "api_with_retries",
  "description": "Calls an API, tries again if it does not answer, and writes a plain note instead of crashing when it stays down. Change the address in the first step to the API you depend on.",
  "tasks": [
    {
      "id": "fetch_data",
      "trigger": "manual",
      "action_type": "http_request",
      "target": "https://api.github.com/repos/golang/go",
      "payload": {
        "method": "GET"
      },
      "retries": 3,
      "output": {
        "store_as": "api_result",
        "pass_to_next": true
      },
      "next": {
        "on_success": "save_result",
        "on_failure": "write_failure_note"
      }
    },
    {
      "id": "write_failure_note",
      "trigger": "event:prev_failure",
      "action_type": "file_op",
      "target": "{{desktop_dir}}/api_failure_note.md",
      "payload": {
        "operation": "write",
        "content": "# The API did not answer\n\nChecked on {{date}}. The request was retried and still failed, so nothing was saved this run. Yesterday's file is untouched.\n"
      },
      "next": "finish"
    },
    {
      "id": "save_result",
      "trigger": "event:prev_success",
      "action_type": "file_op",
      "target": "{{desktop_dir}}/api_result.json",
      "payload": {
        "operation": "write",
        "content": "{{api_result}}"
      },
      "next": "finish"
    },
    {
      "id": "finish",
      "trigger": "event:always",
      "action_type": "notify",
      "target": "stdout",
      "payload": {
        "message": "Run finished. Look in the output folder for either the saved result or the failure note."
      }
    }
  ]
}
