HTTP
http.request sends one HTTP request and writes the response to the step's stdout or to a file. Use it to call REST APIs, post webhooks, and download files.
To wait until an endpoint is ready instead of reading its response, use wait.http.
Basic Usage
steps:
- id: get_todo
action: http.request
with:
method: GET
url: https://jsonplaceholder.typicode.com/todos/1
format: json
silent: true
output: TODO
- id: show
depends: get_todo
run: echo "${TODO.body.title}"The step succeeds on a 2xx response. With format: json and silent: true, stdout is {"body": {...}}, so output: TODO lets later steps read fields such as ${TODO.body.title}. Without those two fields, stdout holds the status line, the headers, and the raw body.
Status Codes and Exit Codes
A 2xx response succeeds. Any other status fails the step with exit code 1, unless status_exit_codes maps it to another code.
status_exit_codes takes an exact code ("404") or a class ("5xx"). An exact code wins over a class. A status mapped to 0 counts as a success and its response is written like a 2xx response. Use distinct codes so retry_policy and continue_on can treat statuses differently:
steps:
- id: fetch_order
action: http.request
with:
method: GET
url: https://api.example.com/orders/1042
timeout: 30
status_exit_codes:
"404": 0 # A missing order is fine
"429": 75 # Rate limited
"5xx": 75 # Server error
retry_policy:
limit: 3
interval_sec: 5
exit_code: [75]Without the map, a 400 also exits 1, so a plain retry_policy retries client errors too.
Send JSON
steps:
- id: create_order
action: http.request
with:
method: POST
url: https://api.example.com/orders
headers:
Content-Type: application/json
body: '{"sku": "A-100", "quantity": 2}'body is sent as written. Write \$ for a literal $ that Dagu must not resolve; see Quoting and Escaping.
Add Query Parameters and Credentials
secrets:
- name: API_TOKEN
ref: prod/api-token
steps:
- id: search
action: http.request
with:
method: GET
url: https://api.example.com/search
headers:
Authorization: "Bearer ${env.API_TOKEN}"
query:
q: invoices
limit: "10"headers and query values are strings, so quote numbers. The secret value is masked in logs; see Secrets.
Upload Files
files and form send a multipart request. Keys are the field names the server expects.
steps:
- id: upload_report
action: http.request
with:
method: POST
url: https://api.example.com/uploads
form:
description: nightly-report
files:
document: ./report.pdfRelative paths resolve from the step's working directory. Dagu sets the multipart Content-Type header and boundary, so do not set it. body cannot be combined with form or files.
Download to a File
with.output writes the response body to a file instead of stdout:
steps:
- id: download_script
action: http.request
with:
method: GET
url: https://example.com/install.sh
output: ${context.paths.artifacts_dir}/install.sh
- id: run_script
depends: download_script
run: sh ${context.paths.artifacts_dir}/install.sh- The file receives only the body bytes. Without
silent: true, stdout still gets the status line and headers. - Relative paths resolve from the step's working directory, and missing parent directories are created.
- The file is replaced only after a successful response. A failed response leaves an existing file unchanged and writes the error body to stdout.
- A path under
${context.paths.artifacts_dir}turns on artifact storage, and the file appears as a run artifact.
with.output is the file target. The step-level output: still captures stdout into a variable.
Poll an Asynchronous Job
Many APIs accept a job, return a status URL, and finish later. Submit the job in one step, then let a second step poll the status URL with repeat_policy until it reaches a final state:
steps:
- id: submit
action: http.request
with:
method: POST
url: https://api.example.com/jobs
headers:
Content-Type: application/json
body: '{"report": "daily"}'
format: json
silent: true
output: SUBMIT
- id: wait_job
depends: submit
action: http.request
with:
method: GET
url: ${SUBMIT.body.status_url}
format: json
silent: true
output: JOB
retry_policy:
limit: 3 # Tolerate short outages of the status endpoint
interval_sec: 5
repeat_policy:
repeat: until
condition: "${JOB.body.state}"
expected: "re:^(done|failed)$"
interval_sec: 5
backoff: 1.5
max_interval_sec: 60
limit: 120 # Maximum number of polls
- id: check_result
depends: wait_job
run: test "${JOB.body.state}" = "done"expectedtakes there:andnum:prefixes of a precondition. Matching both final states stops polling on a failed job too.- A non-2xx status fails the poll.
retry_policyretries it, and polling continues. - When
limitis reached first, the step stops with the last state it read, andcheck_resultfails.
Call Several Endpoints
foreach runs the request once per item:
steps:
- id: health
foreach:
items:
- https://api.example.com/health
- https://auth.example.com/health
as: url
max_concurrent: 2
steps:
- id: check
action: http.request
with:
method: GET
url: ${foreach.url}
silent: trueTo give each call its own run, logs, and retries, use parallel with a sub-DAG; see Sub-DAGs.
Send a Webhook When the Run Ends
handler_on:
success:
action: http.request
with:
method: POST
url: https://hooks.example.com/workflow-complete
headers:
Content-Type: application/json
body: '{"status": "completed", "dag": "${context.dag.name}"}'
steps:
- id: build
run: make buildSee Lifecycle Handlers for the other events.
Use a Connection
Experimental
Connections need experimental_connections: true in config.yaml. While they are off, a run that names a connection fails before its first step.
connection names a connection whose token the request sends as Authorization: Bearer <token>:
steps:
- id: me
action: http.request
with:
connection: work-api
method: GET
url: https://api.example.com/v1/me
format: jsonThe token goes only over HTTPS to the connection's bound hosts. A 401 refreshes it once and sends the request again. connection cannot be combined with debug: true, skip_tls_verify: true, or an Authorization or Host header. See Use Connections in Steps for redirects and errors.
Configuration
| Field | Required | Default | Description |
|---|---|---|---|
method | Yes | HTTP method, such as GET or POST. Case-insensitive. | |
url | Yes | Request URL. | |
headers | No | Request headers. Values are strings. | |
query | No | Query parameters added to the URL. Values are strings. | |
body | No | Request body, sent as written. Cannot be combined with form or files. | |
form | No | Multipart text fields, keyed by field name. | |
files | No | Multipart file paths, keyed by field name. Relative paths resolve from the working directory. | |
timeout | No | None | Request timeout in seconds. Step-level timeout_sec still applies. |
format | No | text | json writes a JSON object to stdout. See Output. |
json | No | false | Same as format: json. |
silent | No | false | On success, write only the body: no status line or headers. |
output | No | File path for the response body. Stdout no longer receives the body. | |
status_exit_codes | No | Map of status code ("300" to "599") or class ("3xx" to "5xx") to exit code (0 to 255). | |
skip_tls_verify | No | false | Accept an untrusted server certificate, such as a self-signed one. |
debug | No | false | Log request and response details. |
connection | No | Experimental. Name of a connection whose token the request sends. A literal, not a reference. |
Output
What stdout holds depends on format, silent, and output:
| Mode | Success | Failure |
|---|---|---|
| Default | Status line, headers, body | Status line, headers, body |
silent: true | Body | Status line, headers, body |
format: json | {status_code, headers, body} | {status_code, headers, body} |
format: json, silent: true | {body} | {status_code, headers, body} |
output: <file> | Status line and headers, or nothing with silent | Status line, headers, error body |
output: <file>, format: json | {status_code, headers, output}, or {output} with silent | {status_code, headers, body} |
In JSON mode, status_code is an integer, each header value is an array of strings, and output is the absolute file path:
{
"status_code": 200,
"headers": { "Content-Type": ["application/json"] },
"body": { "id": 1, "title": "delectus aut autem" }
}A successful response must carry valid JSON, or the step fails. A 204 or 205 with an empty body succeeds and omits body. A failed response whose body is not JSON, such as an HTML error page, reports body as a string.
Errors and Limits
- Missing
methodorurl, an unknownwithfield, or astatus_exit_codeskey or value out of range fails validation. A misspelled field name gets a suggestion. - Redirects are followed, up to 10.
- A timeout or network error fails the step with exit code
1. - Responses are read into memory unless
outputis set. Useoutputfor large downloads.

