These examples are intentionally practical rather than exhaustive. They show a normal REST workflow against a running gateway with a gvmd backend.
The examples assume:
export GVM_GATEWAY_BASE_URL="http://127.0.0.1:8080"
export GVM_GATEWAY_USERNAME="admin"
export GVM_GATEWAY_PASSWORD="admin"For multi-step workflows, these examples use a created session plus bearer token. Single requests can also use HTTP Basic authentication where the gateway accepts it.
The documentation package also includes executable shell examples in the
examples/ directory.
Runs a one-shot scan for a single target host.
The script creates a REST session, chooses or uses the configured scan config, scanner, and port list, creates a target and task, starts the task, waits until the scan finishes, fetches all report results as JSON, creates a PDF report export job, downloads the PDF, and closes the REST session. The created target, task, and report remain in gvmd.
examples/scan-target.sh 192.0.2.10Imports users from a simple CSV file through the REST API.
The script creates a REST session, lists existing users and roles, resolves role
names or UUIDs from the CSV, updates roles for existing users, and creates
missing users with passwords generated by openssl rand -hex 12. Generated
passwords for newly created users are printed to stdout.
The CSV parser intentionally supports only simple CSV: login,roles columns,
no quoted fields, and no commas inside field values. Use | or ; to assign
multiple roles.
examples/import-users.sh examples/users.csvSample input for import-users.sh.
The file contains login,roles rows and demonstrates assigning one role
(alice,User) and multiple roles (bob,User|Observer).
Synchronizes recent Greenbone scan findings into OTOBO.
The Python example reads GVM hosts, recent reports, and report results through
the REST API, syncs hosts to OTOBO CMDB config items, and creates or updates one
OTOBO ticket per stable finding key. It requires OTOBO Generic Interface and
CMDB setup; see examples/otobo/README.md for the required .env values and
OTOBO configuration.
cd examples/otobo
uv run python main.pySynchronizes recent Greenbone scan findings into Jira Cloud.
The Python example reads recent reports and report results through the REST
API, groups results into stable finding keys, and creates or updates one Jira
Cloud issue per finding. It uses the Python Jira SDK, requires a Jira custom
field for GreenboneFindingKey, and does not use Jira Assets or CMDB
integration; see examples/jiracloud/README.md for the required .env values
and Jira Cloud setup.
cd examples/jiracloud
uv run python main.pyAuthenticate with HTTP Basic credentials and capture the returned bearer token:
SESSION_JSON="$(
curl -fsS \
-u "${GVM_GATEWAY_USERNAME}:${GVM_GATEWAY_PASSWORD}" \
-H 'Accept: application/json' \
-X POST \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/session"
)"
SESSION_TOKEN="$(printf '%s' "${SESSION_JSON}" | jq -r '.sessionToken')"
printf '%s\n' "${SESSION_JSON}" | jqExpected fields include:
sessionTokenexpiresIngmpVersion
Check that the service is healthy and learn the exposed gateway version:
curl -fsS "${GVM_GATEWAY_BASE_URL}/gvm/ready" | jq
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/version" | jqMost scan workflows need a scanner, scan config, and port list before creating targets and tasks:
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/scanners?perPage=100" | jq '.data[] | {id, name}'
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/scan-configs?perPage=100" | jq '.data[] | {id, name}'
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/port-lists?perPage=100" | jq '.data[] | {id, name}'Use the returned IDs in the later create calls.
This example uses one host entry and an explicit port list reference:
PORT_LIST_ID="<replace-with-port-list-id>"
TARGET_JSON="$(
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"name": "example-target",
"hosts": ["192.0.2.10"],
"aliveTest": "Consider Alive",
"portListId": "'"${PORT_LIST_ID}"'"
}' \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/targets"
)"
TARGET_ID="$(printf '%s' "${TARGET_JSON}" | jq -r '.id')"
printf '%s\n' "${TARGET_JSON}" | jqUse a target ID, scan config ID, and scanner ID discovered earlier:
SCAN_CONFIG_ID="<replace-with-scan-config-id>"
SCANNER_ID="<replace-with-scanner-id>"
TASK_JSON="$(
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"name": "example-task",
"targetId": "'"${TARGET_ID}"'",
"scanConfigId": "'"${SCAN_CONFIG_ID}"'",
"scannerId": "'"${SCANNER_ID}"'"
}' \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/tasks"
)"
TASK_ID="$(printf '%s' "${TASK_JSON}" | jq -r '.id')"
printf '%s\n' "${TASK_JSON}" | jqcurl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
-X POST \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/tasks/${TASK_ID}/start" | jq
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/tasks/${TASK_ID}" | jqFor longer-running automation, poll GET /gvm/public/v1/tasks/{id} until the task
reaches a terminal backend status such as Done, Stopped, or Error.
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/reports?filter=task_id=${TASK_ID}&perPage=25" | jq '.data[] | {id, reportFormat, task}'Pick the report ID you want to inspect or export.
The gateway exposes report export as a job. This example uses a gvmd PDF report format ID:
REPORT_ID="<replace-with-report-id>"
PDF_REPORT_FORMAT_ID="c402cc3e-b531-11e1-9163-406186ea4fc5"
EXPORT_HEADERS="$(
mktemp
)"
EXPORT_JSON="$(
curl -fsS \
-D "${EXPORT_HEADERS}" \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"reportFormatId": "'"${PDF_REPORT_FORMAT_ID}"'"
}' \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/reports/${REPORT_ID}/exports"
)"
JOB_ID="$(printf '%s' "${EXPORT_JSON}" | jq -r '.jobId')"
printf '%s\n' "${EXPORT_JSON}" | jq
grep -i '^location:' "${EXPORT_HEADERS}"Poll the job, then download the finished artifact:
curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/jobs/${JOB_ID}" | jq
curl -fSLo "report-${REPORT_ID}.pdf" \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/jobs/${JOB_ID}/result"curl -fsS \
-H "Authorization: Bearer ${SESSION_TOKEN}" \
-X DELETE \
"${GVM_GATEWAY_BASE_URL}/gvm/public/v1/session"Use the REST API reference for the human-readable route
map and api/rest/openapi.yaml for the full release-aligned machine contract.