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

# Terminate Mission Early

> Early-terminates an **`in-progress`** mission at a given effective date (**`end_date`**, `YYYY-MM-DD`). If the date is today or in the past, the mission is terminated immediately (status `terminated`). If the date is in the future, the termination is scheduled and finalized automatically on that date. Same business rules as the Folkyn app.




## OpenAPI

````yaml /openapi.yaml post /api/v1/missions/{id}/terminate
openapi: 3.0.3
info:
  title: Folkyn API
  version: 1.0.0
  license:
    name: Proprietary
    url: https://folkyn.com
  description: >-
    Team API key; responses in `data`, errors in `error` with `X-Request-Id`.
    Spec at `/api/v1/openapi.yaml` and `/api/v1/openapi.json` (no key). **60
    requests/minute** per key on `/api/v1/*`.
servers:
  - url: https://api.folkyn.com
    description: Production
security:
  - bearerAuth: []
  - ApiKeyHeader: []
tags:
  - name: Specification
    description: OpenAPI document download (no authentication)
  - name: Project codes
    description: Team project codes
  - name: Team tags
    description: Team tags
  - name: Teams
    description: Organizational teams (team units) and member lists
  - name: Missions
    description: Team missions
  - name: Freelancers
    description: Team freelancers and invitations
  - name: Activity reports
    description: Activity reports (CRA)
  - name: Accounting
    description: Accounting entries
paths:
  /api/v1/missions/{id}/terminate:
    post:
      tags:
        - Missions
      summary: Terminate Mission Early
      description: >
        Early-terminates an **`in-progress`** mission at a given effective date
        (**`end_date`**, `YYYY-MM-DD`). If the date is today or in the past, the
        mission is terminated immediately (status `terminated`). If the date is
        in the future, the termination is scheduled and finalized automatically
        on that date. Same business rules as the Folkyn app.
      operationId: terminateMission
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MissionTerminateRequest'
            examples:
              terminate_today:
                summary: Terminate immediately (today)
                value:
                  end_date: '2026-06-29'
                  reason: Client ended the engagement early.
              schedule_future:
                summary: Schedule termination on a future date
                value:
                  end_date: '2026-08-31'
      responses:
        '200':
          description: Success — same object as GET /api/v1/missions/{id}
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/MissionDetail'
        '400':
          description: >-
            Validation (missing/invalid end_date, mission not in-progress,
            already terminated/scheduled).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ForbiddenError'
        '404':
          description: Mission not found for this team
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    MissionTerminateRequest:
      type: object
      description: >
        Early-terminate an **`in-progress`** mission. `end_date` is the
        effective end date.

        Today/past → immediate termination; future → scheduled and finalized on
        that date.
      properties:
        end_date:
          type: string
          format: date
          description: >
            Effective end date (`YYYY-MM-DD`). Must be **>= today (UTC)**, **>=
            mission start date**, and **<= current mission end date**.
        reason:
          type: string
          nullable: true
          description: Optional free-text reason kept on the mission for your records.
      required:
        - end_date
    MissionDetail:
      $ref: '#/components/schemas/MissionListItemPublic'
    PublicError:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: integer
              description: Same as HTTP status; use `message` and `details` to narrow.
              enum:
                - 400
                - 401
                - 403
                - 404
                - 429
                - 500
              example: 401
            message:
              type: string
            request_id:
              type: string
              format: uuid
              description: Correlates with the X-Request-Id response header.
            details:
              $ref: '#/components/schemas/PublicErrorDetails'
    MissionListItemPublic:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        description:
          type: string
          nullable: true
        mission_type:
          $ref: '#/components/schemas/MissionBillingType'
        contract_kind:
          type: string
          description: >
            Contract channel: **`master_agreement`** = framework agreement path,
            **`services_agreement`** = standalone services agreement. Only these
            two values are returned.
          enum:
            - master_agreement
            - services_agreement
        has_document:
          type: boolean
        currency:
          type: string
          description: >-
            ISO 4217 alphabetic code (e.g. `EUR`, `USD`) as stored on the
            mission.
          example: EUR
        rate_amount:
          type: number
          description: >
            Unit price in **`currency`** according to **`mission_type`**: per
            hour, per day, per month, or mission-level reference for deliverable
            missions (see `MissionBillingType`). Not a daily rate derived by
            dividing elsewhere — the unit is implied by `mission_type`.
        client_rate_amount:
          type: number
          nullable: true
          description: >
            ESN teams only: unit price excl. VAT billed to the end client for
            the same unit as **`rate_amount`** (per hour, day, or month per
            **`mission_type`**). Null for non-ESN teams, deliverable missions,
            or when unset.
        start_date:
          type: string
          format: date
        end_date:
          type: string
          format: date
        display_status:
          $ref: '#/components/schemas/MissionDisplayStatus'
        external_referent:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/ActivityReportExternalReferentPublic'
        purchase_order:
          type: string
          nullable: true
        external_id:
          type: string
          nullable: true
          description: >-
            External identifier for the mission set by the team (e.g. an ERP or
            third-party system reference); null if unset.
        project_code_id:
          type: string
          format: uuid
          nullable: true
        project_code:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/ActivityReportMissionProjectCodePublic'
          description: Linked project code; null if the mission has none.
        deliverables_catalog:
          type: array
          description: >
            Mission deliverables catalog. Empty on **`GET /api/v1/missions`**;
            filled on **`GET /api/v1/missions/{id}`**.
          items:
            $ref: '#/components/schemas/MissionDeliverableCatalogItem'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        created_by:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/PartnerPerson'
        freelancer:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/MissionFreelancerPublic'
        team_signer:
          type: object
          nullable: true
          allOf:
            - $ref: '#/components/schemas/PartnerPerson'
    PublicErrorDetails:
      type: object
      description: Optional structured hints (validation, scope, rate limit).
      additionalProperties: true
      properties:
        reason:
          $ref: '#/components/schemas/PartnerValidationErrorReason'
        field:
          type: string
          description: JSON body field name when applicable (e.g. `name`).
          example: name
        requiredScope:
          type: string
          description: >-
            Required OAuth-like scope string when `code` is 403 (insufficient
            scope).
          example: tags:write
        retryAfterSeconds:
          type: integer
          minimum: 0
          description: Hint when `code` is 429.
    MissionBillingType:
      type: string
      description: >
        Billing model for the mission (Postgres enum `mission_type`). `hourly` /
        `daily` / `monthly` use **`rate_amount`** as the price per that unit in
        **`currency`**. `deliverable` missions bill via the **deliverables
        catalog** (quantities and line amounts); `rate_amount` may still be set
        as a reference but line totals come from catalog rows on mission detail.
      enum:
        - hourly
        - daily
        - monthly
        - deliverable
    MissionDisplayStatus:
      type: string
      description: >
        Derived status for list and detail views (may differ from the stored
        mission status). Based on dates, pending documents, and pending addenda.
      enum:
        - draft
        - awaiting-freelancer-acceptance
        - awaiting-company-signature
        - in-progress
        - upcoming
        - completed
        - early-terminated
        - cancelled
        - rejected
        - deleted
        - pending-company-review
        - pending-freelancer-review
        - pending-freelancer-extension
        - pending-freelancer-signature
    ActivityReportExternalReferentPublic:
      type: object
      required:
        - id
        - email
        - company
        - siren
        - address
        - postal_code
        - city
      description: >-
        External client referent on the mission (id, email, company name, SIREN,
        address fields). Distinct from `freelancer.referent` (team referent).
      properties:
        id:
          type: string
          format: uuid
          nullable: true
          description: Client company UUID; null when unset.
        email:
          type: string
        company:
          type: string
        siren:
          type: string
          nullable: true
          pattern: ^[0-9]{9}$
          description: >-
            Client company SIREN (9 digits, no spaces); null when unset or fewer
            than 9 digits.
        address:
          type: string
          nullable: true
          description: Street address line.
        postal_code:
          type: string
          nullable: true
        city:
          type: string
          nullable: true
    ActivityReportMissionProjectCodePublic:
      type: object
      required:
        - id
        - name
        - external_id
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        external_id:
          type: string
          nullable: true
          description: Optional client / ERP reference for the project code.
    MissionDeliverableCatalogItem:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        quantity:
          type: integer
        amount_excl_vat:
          type: number
        order_index:
          type: integer
    PartnerPerson:
      type: object
      properties:
        id:
          type: string
          format: uuid
        first_name:
          type: string
        last_name:
          type: string
    MissionFreelancerPublic:
      type: object
      description: >
        Assigned freelancer. `referent` is the team member assigned as referent
        for this freelancer, when configured — not the external client referent
        on the mission.
      properties:
        id:
          type: string
          format: uuid
        first_name:
          type: string
        last_name:
          type: string
        email:
          type: string
        referent:
          type: object
          nullable: true
          description: Team referent (id, name, email); null if none.
          allOf:
            - $ref: '#/components/schemas/PartnerFreelancerReferentPublic'
    PartnerValidationErrorReason:
      type: string
      description: >-
        Machine-readable validation subtype (HTTP 400) for create tag / project
        code.
      enum:
        - invalid_json
        - required_field
        - duplicate_name
    PartnerFreelancerReferentPublic:
      type: object
      description: Team referent (id, first name, last name, email).
      required:
        - id
        - first_name
        - last_name
        - email
      properties:
        id:
          type: string
          format: uuid
        first_name:
          type: string
        last_name:
          type: string
        email:
          type: string
  responses:
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicError'
    ForbiddenError:
      description: Insufficient scope or forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicError'
    RateLimited:
      description: Too many requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicError'
    InternalError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: 'Use `Authorization: Bearer <your_api_key>`'
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-Api-Key

````