openapi: 3.1.0
info:
  title: FileRelay developer API
  version: "1.0"
  license:
    name: Proprietary
  summary: SAP documents, live SAP records and their files, and the calls FileRelay makes to you.
  description: |
    The endpoints most integrations use: documents FileRelay received from SAP, the Data API
    (live SAP OData records and files), and the calls FileRelay makes to your endpoints.
    The full API (repositories, destinations, connections, members, certificates, RFC,
    request audit) is described in the in-app API reference at /docs/api/overview.
servers:
  - url: https://filerelay.dev/api
    description: Replace the host with your FileRelay installation
security:
  - apiKey: []
tags:
  - name: Workspaces
  - name: Documents
    description: Documents FileRelay received from SAP (ArchiveLink, CMIS, OData, SAP ILM)
  - name: Data API
    description: Live, read-only SAP OData records and files, for the entity sets enabled on a repository

paths:
  /me/workspaces:
    get:
      operationId: listWorkspaces
      tags: [Workspaces]
      summary: Workspaces this API key can address
      responses:
        "200":
          description: Workspaces with their slug and the caller's role
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        slug: { type: string, example: acme }
                        name: { type: string }
                        role: { type: string, enum: [owner, admin, member, viewer] }
        "401": { $ref: "#/components/responses/Unauthorized" }

  /{workspaceSlug}/documents:
    get:
      operationId: listDocuments
      tags: [Documents]
      summary: List documents
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - { name: page, in: query, schema: { type: integer, minimum: 1, default: 1 } }
        - { name: per_page, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: repo_id, in: query, description: Source repository ID, schema: { type: string } }
        - { name: status, in: query, schema: { type: string, enum: [pending, delivered, failed, retrying] } }
        - { name: date_from, in: query, description: Received on or after (ISO 8601), schema: { type: string, format: date-time } }
        - { name: date_to, in: query, description: Received on or before (ISO 8601), schema: { type: string, format: date-time } }
      responses:
        "200":
          description: A page of documents
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/Document" } }
                  meta: { type: object, description: Pagination }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }

  /{workspaceSlug}/documents/{id}:
    get:
      operationId: getDocument
      tags: [Documents]
      summary: Get one document with its metadata and deliveries
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/documentId"
      responses:
        "200":
          description: The document
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { $ref: "#/components/schemas/Document" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /{workspaceSlug}/documents/{id}/content:
    get:
      operationId: getDocumentContent
      tags: [Documents]
      summary: Download the document's file
      description: Served from FileRelay's buffer, or from a content-server copy once the buffer is cleared.
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/documentId"
      responses:
        "200":
          description: The file bytes
          headers:
            X-Content-Source: { schema: { type: string }, description: "`buffer`, or `destination:<name>`" }
            X-Content-Verified: { schema: { type: string, enum: ["true", "false"] } }
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /{workspaceSlug}/documents/{id}/signed-url:
    get:
      operationId: getDocumentSignedUrl
      tags: [Documents]
      summary: A time-limited download link for the document
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/documentId"
        - { name: expires_in, in: query, description: Lifetime in seconds, schema: { type: integer } }
      responses:
        "200":
          description: The signed URL and its expiry
          content:
            application/json:
              schema: { type: object, properties: { data: { type: object } } }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "404": { $ref: "#/components/responses/NotFound" }

  /{workspaceSlug}/repositories/{id}/odata/{entitySet}:
    get:
      operationId: listSapRecords
      tags: [Data API]
      summary: List SAP records
      description: Only the fields mapped for this entity set are returned. Requires role owner, admin or member, and scope `odata:read` on scoped keys.
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/repositoryId"
        - $ref: "#/components/parameters/entitySet"
        - { name: $top, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
        - { name: $skip, in: query, schema: { type: integer, minimum: 0, default: 0 } }
        - name: $filter
          in: query
          description: "Up to 500 characters: `field eq|ne|gt|ge|lt|le 'text'|number`, joined with `and`/`or`; `contains(doc_id, 'text')` when a `doc_id` field is mapped. Field names are the API names."
          schema: { type: string, maxLength: 500 }
        - { name: $orderby, in: query, description: "One API field name, optionally `asc` or `desc`", schema: { type: string } }
      responses:
        "200":
          description: A page of records
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { $ref: "#/components/schemas/RecordPage" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/DataApiNotFound" }
        "422": { $ref: "#/components/responses/Invalid" }
        "429": { $ref: "#/components/responses/Throttled" }
        "502": { description: SAP returned an error }
        "503": { description: The repository's SAP connection is not configured correctly }

  /{workspaceSlug}/repositories/{id}/odata/{entitySet}/entity:
    get:
      operationId: getSapRecord
      tags: [Data API]
      summary: Read one SAP record by key
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/repositoryId"
        - $ref: "#/components/parameters/entitySet"
        - $ref: "#/components/parameters/keys"
      responses:
        "200":
          description: The record
          content:
            application/json:
              schema:
                type: object
                properties:
                  data: { $ref: "#/components/schemas/Record" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/DataApiNotFound" }
        "422": { $ref: "#/components/responses/Invalid" }
        "429": { $ref: "#/components/responses/Throttled" }

  /{workspaceSlug}/repositories/{id}/odata/{entitySet}/content:
    get:
      operationId: getSapRecordContent
      tags: [Data API]
      summary: Download a SAP record's file
      description: Available when the entity set has file content configured.
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/repositoryId"
        - $ref: "#/components/parameters/entitySet"
        - $ref: "#/components/parameters/keys"
      responses:
        "200":
          description: The file bytes, with SAP's content type
          headers:
            Content-Disposition: { schema: { type: string, example: attachment } }
            X-Content-Type-Options: { schema: { type: string, example: nosniff } }
          content:
            application/octet-stream:
              schema: { type: string, format: binary }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "403": { $ref: "#/components/responses/Forbidden" }
        "404": { $ref: "#/components/responses/DataApiNotFound" }
        "422": { $ref: "#/components/responses/Invalid" }
        "429": { $ref: "#/components/responses/Throttled" }

  /{workspaceSlug}/repositories/{id}/odata/{entitySet}/describe:
    get:
      operationId: describeEntitySet
      tags: [Data API]
      summary: The fields, keys and operations of an entity set
      description: Answers from the mapping; does not call SAP.
      parameters:
        - $ref: "#/components/parameters/workspaceSlug"
        - $ref: "#/components/parameters/repositoryId"
        - $ref: "#/components/parameters/entitySet"
      responses:
        "200":
          description: The entity set's description
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      entity_set: { type: string }
                      fields: { type: array, items: { type: string } }
                      keys: { type: object, additionalProperties: { type: string, enum: [string, integer, guid] } }
                      operations: { type: array, items: { type: string, enum: [list, entity, content] } }
                      odata_version: { type: string, enum: [v2, v4] }
        "404": { $ref: "#/components/responses/DataApiNotFound" }

webhooks:
  workspaceEvent:
    post:
      operationId: workspaceEvent
      security: []
      summary: Workspace notification (success or failure channel)
      description: Sent when a workspace notification channel is set to Webhook.
      requestBody:
        content:
          application/json:
            schema: { $ref: "#/components/schemas/WorkspaceEvent" }
      responses:
        "2XX": { description: Accepted. Anything else is retried up to 3 times. }
  httpDestinationData:
    post:
      operationId: httpDestinationData
      security: []
      summary: HTTP destination, "Data only"
      description: One document's details and SAP metadata, with links to fetch the file. "Data and content" and "Content only" send the file instead (multipart, JSON with base64, or raw bytes).
      requestBody:
        content:
          application/json:
            schema: { $ref: "#/components/schemas/DataOnlyDelivery" }
      responses:
        "2XX": { description: Delivered. Anything else is retried. }

components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: An API key from your user settings (`fr_…`). It acts with your role in the addressed workspace.
  parameters:
    workspaceSlug: { name: workspaceSlug, in: path, required: true, schema: { type: string }, example: acme }
    documentId: { name: id, in: path, required: true, description: Document ID (ULID), schema: { type: string } }
    repositoryId: { name: id, in: path, required: true, description: Repository ID (ULID), schema: { type: string } }
    entitySet: { name: entitySet, in: path, required: true, schema: { type: string, pattern: "^[A-Za-z_][A-Za-z0-9_]*$" } }
    keys:
      name: keys
      in: query
      required: true
      style: deepObject
      explode: true
      description: Every configured key, e.g. `keys[InvoiceNo]=5100000042`
      schema: { type: object, additionalProperties: { type: string, maxLength: 512 } }
  responses:
    Unauthorized: { description: Missing or invalid API key }
    Forbidden: { description: The role or the key's scopes do not allow this }
    NotFound: { description: Not found in this workspace }
    DataApiNotFound: { description: Not an active OData repository, the Data API is off, or the entity set is not enabled }
    Invalid: { description: Unsupported parameter, invalid filter, or keys that do not match }
    Throttled:
      description: SAP is throttling
      headers:
        Retry-After: { schema: { type: integer } }
  schemas:
    Document:
      type: object
      description: See /docs/api/documents for every field.
      properties:
        id: { type: string }
        doc_id: { type: string }
        repo_id: { type: string }
        status: { type: string }
        mime_type: { type: string }
        created_at: { type: string, format: date-time }
      additionalProperties: true
    Record:
      type: object
      properties:
        fields: { type: object, description: Mapped fields by API name, additionalProperties: true }
        keys: { type: object, additionalProperties: true }
        content_available: { type: boolean }
    RecordPage:
      type: object
      properties:
        source: { type: string, const: live_sap }
        repository: { type: string }
        entity_set: { type: string }
        top: { type: integer }
        skip: { type: integer }
        has_more: { type: boolean }
        next_skip: { type: [integer, "null"] }
        items: { type: array, items: { $ref: "#/components/schemas/Record" } }
    WorkspaceEvent:
      type: object
      required: [event, doc_id, workspace]
      properties:
        event: { type: string, enum: [delivery.failed, enrichment.failed, document.stalled, document.processed] }
        doc_id: { type: string }
        workspace: { type: string }
      additionalProperties: true
    DataOnlyDelivery:
      type: object
      required: [document]
      properties:
        document:
          type: object
          properties:
            id: { type: string }
            doc_id: { type: string }
            repository: { type: string }
            source: { type: string }
            sap_object_type: { type: string }
            sap_object_id: { type: string }
            file_name: { type: string }
            mime_type: { type: string }
            size: { type: integer }
            sha256: { type: string }
            received_at: { type: string, format: date-time }
        metadata: { type: object, additionalProperties: { type: string } }
        subfolder: { type: string }
        links:
          type: object
          properties:
            document: { type: string, format: uri }
            content: { type: string, format: uri }
