Skip to main content

Sample code

These examples run a complete cycle: add a target, start a passive scan, wait for the end, then download the PDF report. Set SECUP_API_KEY in your environment first.

Shell (curl and jq)​

API=https://platform.secup.app/api/v1
H="X-SECUP-API-KEY: $SECUP_API_KEY"

# 1. Add the target (409 if it already exists)
TARGET=$(curl -s -X POST $API/targets -H "$H" -H "Content-Type: application/json" \
-d '{"value": "https://shop.example.dz", "tags": ["production"]}' | jq -r .id)

# 2. Start a scan
SCAN=$(curl -s -X POST $API/scans -H "$H" -H "Content-Type: application/json" \
-d "{\"name\": \"CI check\", \"scan_types\": [\"WEB_PASSIVE\", \"HEADERS\", \"TLS\"], \"target_ids\": [\"$TARGET\"]}" | jq -r .id)

# 3. Wait for the end
while :; do
STATE=$(curl -s $API/scans/$SCAN -H "$H" | jq -r .state)
case $STATE in QUEUED|RUNNING|STOPPING) sleep 30 ;; *) break ;; esac
done
echo "Scan finished: $STATE"

# 4. Download the report of that scan
curl -s -G $API/reports -H "$H" --data-urlencode "format=pdf" --data-urlencode "scan_id=$SCAN" -o report.pdf

Python​

import os, time, requests

API = "https://platform.secup.app/api/v1"
s = requests.Session()
s.headers["X-SECUP-API-KEY"] = os.environ["SECUP_API_KEY"]

target = s.post(f"{API}/targets", json={"value": "https://shop.example.dz", "tags": ["production"]}).json()
scan = s.post(f"{API}/scans", json={
"name": "CI check",
"scan_types": ["WEB_PASSIVE", "HEADERS", "TLS"],
"target_ids": [target["id"]],
}).json()

while (state := s.get(f"{API}/scans/{scan['id']}").json()["state"]) in ("QUEUED", "RUNNING", "STOPPING"):
time.sleep(30)
print("Scan finished:", state)

high = s.get(f"{API}/risks", params={"target_id": target["id"], "status": "OPEN", "severity": "CRITICAL,HIGH"}).json()
print(high["total"], "critical or high risks open")

Node.js (18 or later)​

const API = 'https://platform.secup.app/api/v1';
const headers = { 'X-SECUP-API-KEY': process.env.SECUP_API_KEY, 'Content-Type': 'application/json' };
const call = async (path, init = {}) => {
const r = await fetch(API + path, { headers, ...init });
if (!r.ok) throw new Error(`${r.status} ${(await r.json()).error}`);
return r.json();
};

const target = await call('/targets', { method: 'POST', body: JSON.stringify({ value: 'https://shop.example.dz' }) });
const scan = await call('/scans', { method: 'POST', body: JSON.stringify({ scan_types: ['WEB_PASSIVE', 'TLS'], target_ids: [target.id] }) });
let state = scan.state;
while (['QUEUED', 'RUNNING', 'STOPPING'].includes(state)) {
await new Promise((r) => setTimeout(r, 30000));
({ state } = await call(`/scans/${scan.id}`));
}
console.log('Scan finished:', state);

Failing a CI pipeline on new critical risks​

Run the scan as above in your pipeline, then fail the job when the scan's target has open critical risks:

COUNT=$(curl -s -G $API/risks -H "$H" --data-urlencode "target_id=$TARGET" \
--data-urlencode "status=OPEN" --data-urlencode "severity=CRITICAL" | jq .total)
[ "$COUNT" -eq 0 ] || { echo "$COUNT critical risk(s) open"; exit 1; }