> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dezerx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ban the user IP address

> Bans the last known IP address of the user (`ip` field), suspends the account with the reason `IP banned: <reason>` and signs out all of the user sessions.

**Permission:** `users.ip`



## OpenAPI

````yaml /docs/users-api.yaml post /users/{user}/ip-ban
openapi: 3.1.0
info:
  title: Spartan Users API
  version: '2026.11'
  description: >-
    Users, balances, suspensions, IP bans and sessions. Also holds the token
    endpoint you can use to test a key.


    All requests need an API key from **Admin, API** in the `Authorization:
    Bearer <key>` header. Replace `{domain}` with the domain of your Spartan
    installation. Successful responses use the envelope `{"data": ..., "meta":
    {"request_id": ...}}`; errors use `{"error": {"code", "message", "details"},
    "request_id"}`.
servers:
  - url: https://{domain}/api/application
    description: Your Spartan installation
    variables:
      domain:
        default: billing.example.com
        description: Domain of your Spartan installation, without https://
security:
  - bearerAuth: []
tags:
  - name: Token
  - name: Users
  - name: User actions
paths:
  /users/{user}/ip-ban:
    post:
      tags:
        - User actions
      summary: Ban the user IP address
      description: >-
        Bans the last known IP address of the user (`ip` field), suspends the
        account with the reason `IP banned: <reason>` and signs out all of the
        user sessions.


        **Permission:** `users.ip`
      operationId: banUserIp
      parameters:
        - name: user
          in: path
          required: true
          description: User id.
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
                  maxLength: 500
                duration:
                  type:
                    - string
                    - 'null'
                  enum:
                    - 1_hour
                    - 6_hours
                    - 1_day
                    - 1_week
                    - 1_month
                    - permanent
                    - null
                  description: Omit or `permanent` for no expiry.
                banned_by_user_id:
                  type: integer
                  description: Staff user recorded as the actor.
              required:
                - reason
                - banned_by_user_id
            example:
              reason: Repeated fraud attempts
              duration: 1_week
              banned_by_user_id: 2
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/User'
                  message:
                    type: string
                    description: Human readable confirmation.
                  meta:
                    $ref: '#/components/schemas/Meta'
                required:
                  - data
                  - meta
              example:
                data:
                  id: 192
                  name: Jane A. Cooper
                  email: jane.cooper@example.com
                  role: user
                  avatar: /assets/default-avatar.png
                  banner: null
                  footer_message: Thanks, Jane
                  contact_info:
                    phone: +1 555 0100
                    company: Cooper Hosting LLC
                    country: US
                  balance: 25
                  loyalty_points: 0
                  customer_pin: DX-926037
                  subscribed_to_emails: false
                  email_verified_at: '2026-11-16T14:33:49.000000Z'
                  phone_verified_at: null
                  two_factor_enabled: false
                  linked_accounts:
                    discord: null
                    google: null
                    github: null
                  suspension:
                    is_suspended: true
                    reason: 'IP banned: Repeated fraud attempts'
                    suspended_at: '2026-11-16T14:33:49.000000Z'
                    expires_at: '2026-11-23T14:33:49.000000Z'
                  billing:
                    stripe_customer_id: null
                    payment_method_type: null
                    payment_method_last_four: null
                    payment_method_notes: null
                  ip: 203.0.113.24
                  created_at: '2026-11-16T14:33:49.000000Z'
                  updated_at: '2026-11-16T14:33:49.000000Z'
                  counts: []
                message: User IP banned.
                meta:
                  request_id: 76235796-c371-4107-ae5e-839b53b7d4cc
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: Conflict with the current state.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                ip_already_banned:
                  summary: IP already banned
                  value:
                    error:
                      code: ip_already_banned
                      message: The user IP address is already banned.
                      details: {}
                    request_id: c10e02e8-6c11-431b-a643-7744437b83f4
                missing_ip:
                  summary: No IP on record
                  value:
                    error:
                      code: missing_ip
                      message: The user has no recorded IP address.
                      details: {}
                    request_id: 3f6c2a1e-8b4d-4f7a-9c2e-5d1b7a9e0c42
        '422':
          description: Validation failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
              examples:
                validation_failed:
                  summary: Invalid input
                  value:
                    error:
                      code: validation_failed
                      message: The request data is invalid.
                      details:
                        reason:
                          - The reason field is required.
                    request_id: 3f6c2a1e-8b4d-4f7a-9c2e-5d1b7a9e0c42
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          description: User id.
        name:
          type: string
          description: Display name.
        email:
          type: string
          format: email
          description: Email address.
        role:
          type: string
          description: Admin role name. `user` for customers.
        admin_role:
          type:
            - object
            - 'null'
          properties:
            name:
              type: string
            display_name:
              type: string
          description: Role details. Present on list, show, create and update responses.
        avatar:
          type:
            - string
            - 'null'
          description: Avatar path or URL.
        banner:
          type:
            - string
            - 'null'
          description: Profile banner path or URL.
        footer_message:
          type:
            - string
            - 'null'
          description: Signature shown under the user ticket replies.
        contact_info:
          type: object
          properties: {}
          description: >-
            Free form contact details (phone, company, address, country). An
            empty array when nothing is stored.
          additionalProperties: true
        balance:
          type: number
          description: Account credit balance in the base currency.
        loyalty_points:
          type: integer
          description: Loyalty points.
        customer_pin:
          type:
            - string
            - 'null'
          description: Support PIN the customer gives to staff.
        subscribed_to_emails:
          type: boolean
          description: Marketing email opt in.
        email_verified_at:
          type:
            - string
            - 'null'
          format: date-time
        phone_verified_at:
          type:
            - string
            - 'null'
          format: date-time
        two_factor_enabled:
          type: boolean
          description: Two factor authentication is on.
        linked_accounts:
          type: object
          properties:
            discord:
              type:
                - string
                - 'null'
              description: Discord user id.
            google:
              type:
                - string
                - 'null'
              description: Google account id.
            github:
              type:
                - string
                - 'null'
              description: GitHub account id.
        suspension:
          type: object
          properties:
            is_suspended:
              type: boolean
            reason:
              type:
                - string
                - 'null'
            suspended_at:
              type:
                - string
                - 'null'
              format: date-time
            expires_at:
              type:
                - string
                - 'null'
              format: date-time
              description: '`null` for a permanent suspension.'
        billing:
          type: object
          properties:
            stripe_customer_id:
              type:
                - string
                - 'null'
            payment_method_type:
              type:
                - string
                - 'null'
            payment_method_last_four:
              type:
                - string
                - 'null'
            payment_method_notes:
              type:
                - string
                - 'null'
        ip:
          type:
            - string
            - 'null'
          description: Last known IP address.
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        counts:
          type: object
          properties:
            services:
              type: integer
            tickets:
              type: integer
            invoices:
              type: integer
          description: >-
            Related record counts. Filled on list and show responses, an empty
            array on action responses.
    Meta:
      type: object
      properties:
        request_id:
          type: string
          format: uuid
          description: Request id, also sent in the `X-Request-ID` response header.
      required:
        - request_id
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: >-
                Machine readable error code, for example `unauthorized`,
                `forbidden`, `not_found`, `invalid_service_state`.
            message:
              type: string
              description: Human readable explanation.
            details:
              type: object
              properties: {}
              description: Extra context. An empty object for most errors.
              additionalProperties: true
          required:
            - code
            - message
            - details
        request_id:
          type: string
          format: uuid
          description: >-
            Request id. Also returned in the `X-Request-ID` header. Send your
            own with `X-Request-ID` to correlate logs.
      description: Error envelope returned by every failed request.
      required:
        - error
        - request_id
    ValidationError:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              enum:
                - validation_failed
              description: Always `validation_failed`.
            message:
              type: string
              description: Always `The request data is invalid.`
            details:
              type: object
              properties: {}
              description: >-
                Map of field name to a list of messages. Nested fields use dot
                notation, for example `ticket_ids.0`.
              additionalProperties:
                type: array
                items:
                  type: string
          required:
            - code
            - message
            - details
        request_id:
          type: string
          format: uuid
          description: Request id.
      description: Returned with HTTP 422 when the body or query string fails validation.
      required:
        - error
        - request_id
  responses:
    Unauthorized:
      description: Missing, invalid or inactive API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            missing:
              summary: No Authorization header
              value:
                error:
                  code: unauthorized
                  message: Bearer token required.
                  details: {}
                request_id: 9aca26ca-e06f-4725-8e4b-4385d6c03422
            invalid:
              summary: Unknown or inactive key
              value:
                error:
                  code: unauthorized
                  message: Invalid or inactive token.
                  details: {}
                request_id: 8802a669-6f06-453e-a1d8-0b81621167c3
    Forbidden:
      description: >-
        The key lacks the permission for this endpoint, or the request IP is not
        in the key allow list.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            forbidden:
              summary: Missing permission
              value:
                error:
                  code: forbidden
                  message: Insufficient permissions for this action.
                  details: {}
                request_id: 191c51e1-03a3-448e-8df7-3c584be888b0
            ip_not_allowed:
              summary: IP not allowed
              value:
                error:
                  code: ip_not_allowed
                  message: Access denied from this IP address.
                  details: {}
                request_id: 3f6c2a1e-8b4d-4f7a-9c2e-5d1b7a9e0c42
    NotFound:
      description: The resource in the path does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: not_found
              message: The requested resource was not found.
              details: {}
            request_id: cccbc627-4fd4-4727-889e-fa727c48792c
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key created in Admin, API. Send it as `Authorization: Bearer <key>`.
        Each key has its own permissions and optional IP allow list.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.