nsindocs Search the docs⌘K
  1. Docs
  2. API reference
  3. Domains

Switch Under Attack Mode

puthttps://api.nsin.ir/domains/{domain}/under-attack

Auth: Authorization: Bearer nsin_… or X-Api-Key: nsin_… — see API keys.

While Under Attack Mode is on, every visitor solves a short check before reaching the site — except on bypass_paths (mobile-app and API paths that cannot run a browser) and verified good bots (search engines). A solved check is remembered for the edge's default clearance time.

The switch keeps one managed captcha rule on the domain (managed_by: under_attack, priority 1, zone-wide, path_excludes = bypass_paths). Rule endpoints list it but refuse to edit, delete, toggle or reorder it (403); it does not count against any rule limit. Switching off removes it.

Every field is optional; a missing one keeps its value. auto_off_minutes (0 = never, 60, 360 or 1440) restarts the auto-off timer from now while the mode is on; switching on without it starts with no timer. Switching on needs a plan with under_attack_allowed (every plan by default); switching off is always allowed. The change reaches the edge with the next records sync. Requires domain.settings.

Path parameters

  • domainstringrequiredpath

    The domain name (for example example.com) — not a numeric id.

Request body

Content type: application/json · required

  • enabledboolean
  • bypass_pathsarray of string

    Wildcard path patterns, each starting with / (* matches any characters; /api/* also matches /api). Replaces the list.

  • bypass_ipsarray of string

    Client addresses never challenged: single IPs, CIDRs (10.0.0.0/8) or lo-hi ranges. 0.0.0.0/0 and ::/0 are refused. Replaces the list.

  • bypass_hostsarray of string

    Host names or wildcard patterns never challenged (api.example.com, *.api.example.com), case-insensitive. A bare * is refused. Replaces the list.

  • auto_off_minutesinteger

    Switch off after this many minutes, counted from now; 0 = never.

    One of: 0 60 360 1440

Responses

200The new state.

Content type: application/json

  • enabledboolean
  • bypass_pathsarray of string

    Paths never challenged. Kept while the mode is off, for next time.

  • bypass_ipsarray of string

    Client IPs, CIDRs or ranges never challenged. Kept while the mode is off.

  • bypass_hostsarray of string

    Hosts (wildcard patterns) never challenged. Kept while the mode is off.

  • sincestring | null (date-time)

    When the mode was switched on. Null when off.

  • untilstring | null (date-time)

    When the mode switches itself off. Null when off or with no timer.

  • allowedboolean

    The domain's plan includes Under Attack Mode (under_attack_allowed).

json
{
  "enabled": true,
  "bypass_paths": [
    "string"
  ],
  "bypass_ips": [
    "string"
  ],
  "bypass_hosts": [
    "string"
  ],
  "since": "2026-01-01T00:00:00Z",
  "until": "2026-01-01T00:00:00Z",
  "allowed": true
}
400An invalid auto_off_minutes or bypass path.

Content type: application/json

  • errorstringrequired

    Human-readable description of what went wrong.

json
{
  "error": "read-only API key"
}
401Missing, malformed, revoked or expired API key. (A valid key whose account has been deactivated gets 403 account is inactive instead.)

Content type: application/json

  • errorstringrequired

    Human-readable description of what went wrong.

json
{
  "error": "invalid API key"
}
403The domain's plan does not include Under Attack Mode, or the key lacks domain.settings.

Content type: application/json

  • errorstringrequired

    Human-readable description of what went wrong.

json
{
  "error": "read-only API key"
}
404No such domain, or it is not visible to this account. Domains you cannot access are reported as not found rather than forbidden.

Content type: application/json

  • errorstringrequired

    Human-readable description of what went wrong.

json
{
  "error": "read-only API key"
}
429The key exceeded its request budget (300 requests per minute by default).

Content type: application/json

  • errorstringrequired

    Human-readable description of what went wrong.

json
{
  "error": "rate limit exceeded"
}

Example request

bash
curl -X PUT "https://api.nsin.ir/domains/example.com/under-attack" \
  -H "Authorization: Bearer $NSIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "enabled": true,
  "bypass_paths": [
    "/api/*",
    "/app/*"
  ],
  "auto_off_minutes": 360
}'
esc