openapi: 3.0.1
info:
  contact:
    email: info.ksef@mf.gov.pl
    name: Info
    url: https://ksef.mf.gov.pl
  description: Krajowy System e-Faktur
  title: KSeF
  version: 2.0.0
externalDocs:
  description: Dokumentacja
  url: https://www.gov.pl/web/kas/krajowy-system-e-faktur
servers:
- description: Środowisko produkcyjne
  url: https://ksef.mf.gov.pl/api
  variables: {}
- description: Środowisko demonstracyjne
  url: https://ksef-demo.mf.gov.pl/api
  variables: {}
- description: Środowisko testowe
  url: https://ksef-test.mf.gov.pl/api
  variables: {}
tags:
- description: Krajowy System e-Faktur
  externalDocs:
    description: Krajowy System e-Faktur
    url: https://ksef.mf.gov.pl
  name: KSeF
paths:
  /batch/Finish:
    post:
      description: Finalizacja wysyłki wsadowej paczki faktur
      operationId: batch.finish
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FinishRequest'
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FinishResponse'
          description: Finalizacja wysyłki wsadowej paczki faktur poprawna
        "400":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExceptionResponse'
          description: Nieprawidłowe wywołanie
      summary: Wysyłka wsadowa paczki faktur do KSeF - finalizacja
      tags:
      - Wysyłka wsadowa
  /batch/Init:
    post:
      description: Inicjalizacja wysyłki wsadowej paczki faktur. Podpisany dokument
        http://ksef.mf.gov.pl/schema/gtw/svc/batch/init/request/2021/10/01/0001/InitRequest
      operationId: batch.init
      requestBody:
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
        required: true
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InitResponse'
          description: Inicjalizacja wysyłki wsadowej paczki faktur poprawna
        "400":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExceptionResponse'
          description: Nieprawidłowe wywołanie
      summary: Wysyłka wsadowa paczki faktur do KSeF - inicjalizacja
      tags:
      - Wysyłka wsadowa
  /batch/Upload/{ReferenceNumber}/{PartName}:
    put:
      description: Załadowanie zaszyfrowanych części paczki
      operationId: batch.upload
      parameters:
      - in: path
        name: ReferenceNumber
        required: true
        schema:
          type: string
      - in: path
        name: PartName
        required: true
        schema:
          type: string
      requestBody:
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
        description: Zaszyfrowana część paczki kluczem symetrycznym zadeklarowanym
          w dokumencie Init
        required: true
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UploadResponse'
          description: Załadowanie części paczki poprawne
        "400":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExceptionResponse'
          description: Nieprawidłowe wywołanie
      summary: Wysyłka wsadowa paczki faktur do KSeF - załadowanie części paczki
      tags:
      - Wysyłka wsadowa
components:
  schemas:
    ExceptionDetailType:
      type: object
      properties:
        exceptionCode:
          type: integer
          format: int32
          minimum: 0
        exceptionDescription:
          type: string
          maxLength: 256
          minLength: 1
      required:
      - exceptionCode
      - exceptionDescription
    ExceptionResponse:
      type: object
      properties:
        exception:
          $ref: '#/components/schemas/ExceptionType'
      required:
      - exception
    ExceptionType:
      type: object
      properties:
        exceptionDetailList:
          type: array
          items:
            $ref: '#/components/schemas/ExceptionDetailType'
          maxItems: 100
          minItems: 1
        referenceNumber:
          type: string
          pattern: "(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})"
        serviceCode:
          type: string
          maxLength: 64
          minLength: 1
        serviceCtx:
          type: string
          maxLength: 64
          minLength: 1
        serviceName:
          type: string
          maxLength: 64
          minLength: 1
        timestamp:
          type: string
          format: date-time
      required:
      - exceptionDetailList
      - serviceCode
      - serviceCtx
      - serviceName
      - timestamp
    FinishRequest:
      type: object
      properties:
        referenceNumber:
          type: string
          pattern: "(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})"
      required:
      - referenceNumber
    FinishResponse:
      type: object
      properties:
        referenceNumber:
          type: string
          pattern: "(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})"
        timestamp:
          type: string
          format: date-time
      required:
      - referenceNumber
      - timestamp
    HeaderEntryType:
      type: object
      properties:
        key:
          type: string
          maxLength: 64
          minLength: 1
        value:
          type: string
          maxLength: 128
          minLength: 1
      required:
      - key
      - value
    InitResponse:
      type: object
      properties:
        packageSignature:
          $ref: '#/components/schemas/PackageSignatureInitResponseType'
        referenceNumber:
          type: string
          pattern: "(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})"
        timestamp:
          type: string
          format: date-time
      required:
      - packageSignature
      - referenceNumber
      - timestamp
    PackagePartSignatureInitResponseType:
      type: object
      properties:
        headerEntryList:
          type: array
          items:
            $ref: '#/components/schemas/HeaderEntryType'
          maxItems: 100
          minItems: 1
          uniqueItems: true
        method:
          type: string
          enum:
          - POST
          - PUT
        ordinalNumber:
          type: integer
          format: int32
          minimum: 0
        partFileName:
          type: string
          pattern: "[a-zA-Z0-9_\\.\\-]{5,100}"
        url:
          type: string
          maxLength: 512
          minLength: 1
          pattern: "http[s]?:\\/{2}([0-9a-z][0-9a-z_-]*\\.)+[0-9a-z][0-9a-z_-]*(([0-9a-zA-Z][0-9a-zA-Z_-]*\\\
            .?)*\\/?)*"
      required:
      - method
      - ordinalNumber
      - partFileName
      - url
    PackageSignatureInitResponseType:
      type: object
      properties:
        packageName:
          type: string
          pattern: "[a-zA-Z0-9_\\.\\-]{5,100}"
        packagePartSignatureList:
          type: array
          items:
            $ref: '#/components/schemas/PackagePartSignatureInitResponseType'
          maxItems: 100
          minItems: 1
          uniqueItems: true
      required:
      - packageName
      - packagePartSignatureList
    UploadResponse:
      type: object
      properties:
        referenceNumber:
          type: string
          pattern: "(20[2-9][0-9]|2[1-9][0-9]{2}|[3-9][0-9]{3})(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])-([0-9A-Z]{2})-([0-9A-F]{10})-([0-9A-F]{10})-([0-9A-F]{2})"
        timestamp:
          type: string
          format: date-time
      required:
      - referenceNumber
      - timestamp
