openapi: 3.0.0
info:
  title: Expense Integration API
  version: 0.2-oas3
  contact:
    name: Scalepoint
    url: 'https://dev.scalepoint.com'
    email: dev@scalepoint.com
tags:
  - name: external
    description: API for external partners
paths:
  '/{version}/expense/submit':
    post:
      tags:
        - external
      summary: Submit expense
      operationId: submitExpense
      parameters:
        - name: version
          in: path
          description: API version
          required: true
          schema:
            type: string
            enum:
              - v2
            default: v2
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitExpenseResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubmitExpenseRequest'
        required: true
servers:
  - url: https://entry.scalepoint.com/ecx/host/api/integration
    description: Production server (uses live data)
  - url: https://test.scalepoint.com/ecx/host/api/integration
    description: Test server (uses dummy data but has the same setup and version as Production)
security:
  - bearerAuth: []
components:
  securitySchemes:
      bearerAuth:
        type: http
        scheme: bearer
        bearerFormat: JWT
  schemas:
    SubmitExpenseRequest:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            claim:
              type: object
              properties:
                id:
                  type: string
                tenant:
                  type: string
              required:
                - id
                - tenant
            expense:
              type: object
              properties:
                number:
                  type: string
                invoiceIdentifier:
                  oneOf:
                    - $ref: '#/components/schemas/fik'
                    - $ref: '#/components/schemas/kid'
                date:
                  type: string
                dueDate:
                  type: string
                expenseType:
                  type: string
                  description: >-
                    Possible values are: Invoice - shall be used for Repair and
                    DamageService invoice types, CreditNote, ClaimantOwnWork,
                    PaymentOnAccountInvoice, CashCompensation – shall be used
                    with None invoice type. Note: Only unrelated Credit notes
                    (CN) could be submitted. Related CN are not supported. To
                    submit related CN first submit unrelated draft and then
                    follow to HUB  Property, specify related invoice manually and submit
                    CN.
                invoiceType:
                  type: string
                  description: >-
                    Possible values are: None, Repair, Assessment, Rejection,
                    DamageService, Unrelated, ExternalSupplier
                isDraft:
                  type: boolean
                issuer:
                  $ref: '#/components/schemas/PartyItem'
                payer:
                  $ref: '#/components/schemas/PartyItem'
                items:
                  type: array
                  items:
                    $ref: '#/components/schemas/ExpenseItem'
                subtotal:
                  type: integer
                vat:
                  type: integer
                total:
                  type: integer
                description:
                  type: string
                invoiceRemark:
                  type: string
                externalSupplier:
                  type: object
                  properties:
                    relatedCraftsmanId:
                      type: string
                  required:
                    - relatedCraftsmanId
                extraProperties:
                  type: object
                files:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                      mimeType:
                        pattern: '^[+-\.\w]+/[+-\.\w]+$'
                      size:
                        type: integer
                        minimum: 0
                      description:
                        type: string
                      content:
                        type: string
                    required:
                      - name
                      - mimeType
                      - content
              required:
                - number
                - date
                - expenseType
                - invoiceType
                - isDraft
                - issuer
                - subtotal
                - vat
                - total
          required:
            - expense
            - claim
      required:
        - meta
        - data
    SubmitExpenseResponse:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            expense:
              type: object
              properties:
                url:
                  type: string
                status:
                  type: string
              required:
                - url
                - status
          required:
            - expense
      required:
        - meta
        - data
    ErrorResponse:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            error:
              type: string
          required:
            - error
      required:
        - meta
        - data
    PartyItem:
      type: object
      properties:
        name:
          type: string
        email:
          type: string
        faxNumber:
          type: string
        phoneNumber:
          type: string
        address:
          type: object
          properties:
            street:
              type: string
            street2:
              type: string
            postalCode:
              type: string
            city:
              type: string
            country:
              type: string
          required:
            - street
            - postalCode
            - city
            - country
        companyTaxId:
          type: string
        giro:
          type: string
        bankBranchNumber:
          type: string
        accountNumber:
          type: string
      required:
        - companyTaxId
    ExpenseItem:
      type: object
      properties:
        title:
          type: string
        category:
          type: string
        unit:
          type: string
        quantity:
          type: integer
        unitPrice:
          type: integer
        subtotal:
          type: integer
        vat:
          type: integer
      required:
        - title
        - category
        - unit
        - quantity
        - unitPrice
        - subtotal
        - vat
    fik:
      type: object
      properties:
        type:
          type: string
          minLength: 2
          maxLength: 2
        identifier:
          type: string
          minLength: 15
          maxLength: 15
        creditorNumber:
          type: string
          minLength: 8
          maxLength: 8
      required:
        - type
        - identifier
        - creditorNumber
    kid:
      type: object
      properties:
        kid:
          type: string
          minLength: 2
          maxLength: 25