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

# Apply a discount code

> Applies a discount code to one of your services. A code can be applied to only one service, and a service can have only one active code. Once applied, the discount lasts for the code's `timespan` in days. With `teamID`, this needs the `billing.manage` permission.



## OpenAPI

````yaml /spec/platform-billing.yaml post /v1/discount-codes/apply
openapi: 3.0.1
info:
  title: Billing & Subscription
  version: 1.0.0
  description: |
    Check your balance and costs, add credit, download invoices and receipts,
    manage your subscription plan, and apply discount codes.

    All amounts are in Toman (IRT).

    With `teamID`, these endpoints work on the team's billing. Most of them
    need the `billing.manage` permission in the team; the description of each
    endpoint says which permission it needs.
servers:
  - url: https://api.liara.ir
security:
  - bearerAuth: []
tags:
  - name: Balance & Usage
    description: Balance, current costs and service counts.
  - name: Payments
    description: Add credit and list past payments.
  - name: Invoices & Receipts
    description: Monthly billing invoices and payment receipts.
  - name: Subscription
    description: View and change the account's subscription plan.
  - name: Discount Codes
    description: Check and apply discount codes.
paths:
  /v1/discount-codes/apply:
    post:
      tags:
        - Discount Codes
      summary: Apply a discount code
      description: >-
        Applies a discount code to one of your services. A code can be applied
        to only one service, and a service can have only one active code. Once
        applied, the discount lasts for the code's `timespan` in days. With
        `teamID`, this needs the `billing.manage` permission.
      operationId: applyDiscountCode
      parameters:
        - $ref: '#/components/parameters/TeamID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - code
                - serviceType
                - serviceID
              properties:
                code:
                  type: string
                serviceType:
                  $ref: '#/components/schemas/DiscountServiceType'
                serviceID:
                  type: string
                  pattern: ^[0-9a-fA-F]{24}$
                  description: The service's `_id`.
            example:
              code: <discount-code>
              serviceType: project
              serviceID: '000000000000000000000050'
      responses:
        '200':
          description: The code was applied.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
              example:
                message: >-
                  Discount code applied successfully on project with ID
                  000000000000000000000050
        '400':
          description: >-
            The body or `teamID` is invalid, or the code can't be applied:
            `discount_code_expired`, `discount_code_amount_limit_reached`,
            `discount_code_already_applied`,
            `discount_code_already_applied_to_another_service`,
            `another_active_discount_code` or `discount_code_not_applicable`
            (the code is only for services created after it).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 400
                error: Bad Request
                message: Discount code has expired
                data:
                  code: discount_code_expired
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/TeamForbidden'
        '404':
          description: >-
            The code doesn't exist (`discount_code_not_found`), is for another
            kind of service (`discount_code_service_mismatch`), or the service
            doesn't exist: `project_not_found`, `database_not_found`,
            `bucket_not_found`, `mail_server_not_found`, `vm_not_found` or
            `ai_not_found`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 404
                error: Not Found
                message: Project not found
                data:
                  code: project_not_found
components:
  parameters:
    TeamID:
      name: teamID
      in: query
      required: false
      description: >-
        Run the request in the context of a team you belong to, instead of your
        personal account.
      schema:
        $ref: '#/components/schemas/ObjectID'
      example: '000000000000000000000002'
  schemas:
    DiscountServiceType:
      type: string
      enum:
        - project
        - database
        - mailServer
        - bucket
        - vm
        - ai
    Error:
      type: object
      description: Standard error body.
      properties:
        statusCode:
          type: integer
        error:
          type: string
          description: HTTP status text.
        message:
          type: string
          description: What went wrong.
        data:
          type: object
          nullable: true
          description: >-
            Extra details. When present, `code` is a stable, machine-readable
            error code.
          properties:
            code:
              type: string
    ObjectID:
      type: string
      pattern: ^[0-9a-fA-F]{24}$
      description: 24-character hexadecimal ID.
    AuthError:
      type: object
      description: Error body returned when the API token is rejected.
      properties:
        error:
          type: string
  responses:
    Unauthorized:
      description: The API token is missing, invalid or expired.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AuthError'
          example:
            error: Unauthorized.
    TeamForbidden:
      description: >-
        With `teamID`: you aren't a member of the team (`team_not_found`), or
        your role doesn't have the required permission (`no_permission`).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            teamNotFound:
              summary: Not a team member
              value:
                statusCode: 403
                error: Forbidden
                message: Team not found
                data:
                  code: team_not_found
            noPermission:
              summary: Missing permission
              value:
                statusCode: 403
                error: Forbidden
                message: You do not have permission to access this resource.
                data:
                  code: no_permission
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: 'Send your API token as `Authorization: Bearer <api-token>`.'

````

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