> ## 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.

# Create a service

> Creates a service for a user from a product (`service_type: product`) or as a standalone service (`service_type: custom`). An initial invoice is created. The service starts as `pending`; call activate to provision it.

**Permission:** `services.create`



## OpenAPI

````yaml /docs/service-api.yaml post /services
openapi: 3.1.0
info:
  title: Spartan Service API
  version: '2026.11'
  description: >-
    Services: create, read and update, lifecycle actions, billing and pricing,
    plan changes, notes, members, addons, provider details and dispute evidence.


    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: Services
  - name: Lifecycle
  - name: Billing
  - name: Upgrades
  - name: Notes
  - name: Members
  - name: Addons
  - name: Service details
  - name: Evidence
paths:
  /services:
    post:
      tags:
        - Services
      summary: Create a service
      description: >-
        Creates a service for a user from a product (`service_type: product`) or
        as a standalone service (`service_type: custom`). An initial invoice is
        created. The service starts as `pending`; call activate to provision it.


        **Permission:** `services.create`
      operationId: createService
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                user_id:
                  type: integer
                  description: Owner user id.
                service_type:
                  type: string
                  enum:
                    - product
                    - custom
                  description: >-
                    `product` creates a service from a catalog product, `custom`
                    creates a standalone service.
                product_id:
                  type: integer
                  description: Required when `service_type` is `product`.
                billing_cycle:
                  type: string
                  description: >-
                    Required for `custom`. For `product`, defaults to the first
                    enabled cycle.
                  maxLength: 100
                service_name:
                  type: string
                  description: Required for `custom`.
                  maxLength: 255
                price:
                  type: number
                  description: Required for `custom`. Recurring price.
                  minimum: 0
                category_id:
                  type: integer
                  description: Required for `custom`.
                custom_fields:
                  type: object
                  properties: {}
                  description: Custom only. Extra fields shown on the service page.
                  additionalProperties: true
                custom_buttons:
                  type: array
                  items:
                    type: object
                    properties: {}
                    additionalProperties: true
                  description: Custom only. Buttons shown on the service page.
                due_date:
                  type: string
                  format: date
                  description: First due date, must be after today.
                notes:
                  type:
                    - string
                    - 'null'
                  description: Internal note, up to 5000 characters.
                  maxLength: 5000
              required:
                - user_id
                - service_type
            examples:
              custom:
                summary: Standalone service
                value:
                  user_id: 192
                  service_type: custom
                  service_name: Managed VPS - Jane
                  price: 14.99
                  billing_cycle: monthly
                  category_id: 4
                  due_date: '2026-12-16'
                  notes: Migrated from the old panel
              product:
                summary: From a product
                value:
                  user_id: 192
                  service_type: product
                  product_id: 19
                  billing_cycle: monthly
      responses:
        '201':
          description: Created.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Service'
                  message:
                    type: string
                    description: Human readable confirmation.
                  meta:
                    $ref: '#/components/schemas/Meta'
                required:
                  - data
                  - meta
              example:
                data:
                  id: 908
                  name: Managed VPS - Jane
                  status: pending
                  owner:
                    id: 192
                    name: Jane A. Cooper
                    email: jane.cooper@example.com
                    avatar: /assets/default-avatar.png
                  product: null
                  category:
                    id: 4
                    name: Other plans
                  module: null
                  price: 14.99
                  original_price: null
                  modified_pricing: null
                  billing_cycle: monthly
                  due_date: '2026-12-16T00:00:00.000000Z'
                  auto_renewal_enabled: false
                  provisioned_at: null
                  addons: []
                  created_at: '2026-11-16T14:33:49.000000Z'
                  updated_at: '2026-11-16T14:33:49.000000Z'
                message: Service created.
                meta:
                  request_id: c09cb37f-5bfb-413e-b00b-c7bff563ac3c
        '400':
          description: The provider module rejected the action.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                service_creation_failed:
                  summary: Creation failed
                  value:
                    error:
                      code: service_creation_failed
                      message: The service could not be created.
                      details: {}
                    request_id: 3f6c2a1e-8b4d-4f7a-9c2e-5d1b7a9e0c42
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '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:
                        user_id:
                          - The selected user id is invalid.
                        service_name:
                          - The service name field is required.
                        price:
                          - The price field is required.
                        billing_cycle:
                          - The billing cycle field is required.
                        category_id:
                          - The category id field is required.
                    request_id: a05ef1bd-60ea-494f-bc29-90c17de82bd3
components:
  schemas:
    Service:
      type: object
      properties:
        id:
          type: integer
          description: Service id.
        name:
          type:
            - string
            - 'null'
          description: Service name shown to the customer.
        status:
          type: string
          enum:
            - pending
            - active
            - suspended
            - terminated
            - cancelled
            - past_due
          description: Lifecycle status.
        owner:
          allOf:
            - $ref: '#/components/schemas/UserReference'
          description: Owner. Present on list, show, create and owner change responses.
        product:
          type:
            - object
            - 'null'
          properties:
            id:
              type: integer
            name:
              type: string
            image:
              type:
                - string
                - 'null'
              description: Image path relative to the public storage disk.
          description: >-
            Product the service was ordered from. `null` for standalone (custom)
            services.
        category:
          type:
            - object
            - 'null'
          properties:
            id:
              type: integer
            name:
              type: string
        module:
          type:
            - string
            - 'null'
          description: >-
            Provisioning module, for example `PterodactylService`. `null` for
            services without a module.
        price:
          type:
            - number
            - 'null'
          description: Recurring price per billing cycle.
        original_price:
          type:
            - number
            - 'null'
          description: Price before a coupon or override.
        modified_pricing:
          type:
            - object
            - 'null'
          properties: {}
          description: Per cycle price overrides set with the pricing endpoint.
          additionalProperties: true
        billing_cycle:
          type: string
          description: >-
            Billing cycle key, for example `monthly`, `quarterly`, `yearly` or a
            custom plan key.
        due_date:
          type:
            - string
            - 'null'
          format: date-time
          description: Next due date.
        auto_renewal_enabled:
          type: boolean
        provisioned_at:
          type:
            - string
            - 'null'
          format: date-time
        addons:
          type: array
          items:
            $ref: '#/components/schemas/Addon'
          description: >-
            Purchased addons. The array index is the `index` used by the addon
            endpoints.
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
    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
    UserReference:
      type: object
      properties:
        id:
          type: integer
          description: User id.
        name:
          type: string
          description: Display name.
        email:
          type: string
          format: email
          description: Email address.
        avatar:
          type:
            - string
            - 'null'
          description: Avatar path or URL.
    Addon:
      type: object
      properties:
        addon_id:
          type: integer
          description: Addon id.
        name:
          type: string
          description: Addon name.
        quantity:
          type: integer
          description: Purchased quantity.
        price:
          type: number
          description: Price per unit and billing cycle.
        billing_cycle:
          type: string
        status:
          type: string
          enum:
            - active
            - pending_cancellation
            - cancelled
          description: Addon status.
        module_applied:
          type: boolean
          description: >-
            Whether the provisioning module already applied the addon to the
            server.
      additionalProperties: true
  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
  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.