openapi: 3.0.1
info:
  title: Schedule Service API Specification
  description: |
    This page describes how to integrate with the **Schedule Service** on a technical level.

    -----

    ## REST Resources

    The Schedule Service provides a resource for creating and managing **schedules**.

    ### Scheduled Message

    A **scheduled message** defines a task that will execute at a specific time or interval. It consists of two main parts:
    the **message** payload to be processed and a **crontab** expression that dictates the schedule. This enables the Banqup
    platform to trigger automated actions, such as sending notifications or initiating workflows, at predetermined times.

    An example of a **scheduled message request** in JSON format:

    ```json
    {
      "message": {
        "category": "Document",
        "type": "DocumentCreated",
        "data": {
          "relatedDocumentId": "bb23bbff-7326-462f-80bc-4a3c5d66567e"
        }
      },
      "crontab": "0 9 * * *"
    }
    ```

    When this schedule is created, the service will return the full scheduled message object, including its unique **ID**:

    ```json
    {
      "id": "5f125986-4297-4a9d-b36f-79911b213a65",
      "message": {
        "category": "Document",
        "type": "DocumentCreated",
        "data": {
          "relatedDocumentId": "bb23bbff-7326-462f-80bc-4a3c5d66567e"
        }
      },
      "crontab": "0 9 * * *"
    }
    ```

    The service uses standard crontab expressions for defining schedules, providing flexible and precise control over task
    execution timing.

    -----

    ## Managing Scheduled Messages

    ### Creating a Scheduled Message

    To create a new message schedule, you'll perform a **POST** request to the [**/core/schedule/v1/scheduledMessages
    **](../../../docs/foundation/schedule/create-scheduled-message) endpoint, providing
    the message payload and crontab expression in the request body.

    For example, to schedule a `DocumentCreated` message:

    ```http
    POST /v1/scheduledMessages
    Content-Type: application/json

    {
      "message": {
        "category": "Document",
        "type": "DocumentCreated",
        "data": {
          "relatedDocumentId": "bb23bbff-7326-462f-80bc-4a3c5d66567e"
        }
      },
      "crontab": "0 9 * * *"
    }
    ```

    A successful response (HTTP `201 Created`) will return the newly created scheduled message object, including its unique
    `id`.

    ### Retrieving Scheduled Messages

    You can retrieve a list of all existing message schedules or fetch a specific one by its ID.

    * To get a list of all schedules, perform a **GET** request to the [**/core/schedule/v1/scheduledMessages
      **](../../../docs/foundation/schedule/list-scheduled-messages-1) endpoint. This returns an
      NDJSON stream of scheduled message objects.
    * To retrieve a specific schedule, perform a **GET** request to [**/core/schedule/v1/scheduledMessages/:
      scheduledMessageId**](../../../docs/foundation/schedule/retrieve-scheduled-message), providing its unique
      identifier.

    For example, to retrieve a specific schedule:

    ```http
    GET /v1/scheduledMessages/5f125986-4297-4a9d-b36f-79911b213a65
    ```

    A successful response (HTTP `200 OK`) will return the full scheduled message object.

    ### Updating a Scheduled Message

    To update an existing schedule, perform a **PUT** request to [**/core/schedule/v1/scheduledMessages/:scheduledMessageId
    **](../../../docs/foundation/schedule/update-scheduled-message), providing the full, updated
    scheduled message object in the request body.

    For example, to change the `crontab` for an existing schedule:

    ```http
    PUT /v1/scheduledMessages/5f125986-4297-4a9d-b36f-79911b213a65
    Content-Type: application/json

    {
      "message": {
        "category": "Document",
        "type": "DocumentCreated",
        "data": {
          "relatedDocumentId": "bb23bbff-7326-462f-80bc-4a3c5d66567e"
        }
      },
      "crontab": "0 9 * * *"
    }
    ```

    A successful update will return an HTTP `200 OK` response with the updated object.

    ### Deleting a Scheduled Message

    To delete a message schedule, perform a **DELETE** request to [**/core/schedule/v1/scheduledMessages/:scheduledMessageId
    **](../../../docs/foundation/schedule/delete-scheduled-message).

    ```http
    DELETE /v1/scheduledMessages/5f125986-4297-4a9d-b36f-79911b213a65
    ```

    A successful deletion will return an HTTP `204 No Content` response.

    -----

    ## Security

    Access to create, retrieve, update, and delete scheduled messages is controlled by the **`schedule_manage`** security scope. All requests to the Scheduled Message API must be authenticated using an OAuth security scheme.
    The provided token must meet two conditions:
    1.  It must include the **`schedule_manage`** scope to authorize the request itself.
    2.  It must be eligible for impersonation, allowing the Schedule Service to use it in a **Token Exchange** flow to access other services as the user.
  version: 2.0.1
servers:
- description: ''
  url: https://api.btx.fr.banqup.com/core/schedule
- description: ''
  url: https://api.btx.eu.banqup.com/core/schedule
paths:
  /v1/scheduledMessages/{scheduledMessageId}:
    get:
      tags:
      - Scheduled Message
      summary: Retrieve a specific message schedule
      operationId: retrieveScheduledMessage
      parameters:
      - name: scheduledMessageId
        in: path
        description: The unique identifier of the message schedule
        required: true
        schema:
          type: string
          description: The unique identifier of the message schedule
          format: uuid
          example: 5f125986-4297-4a9d-b36f-79911b213a65
        example: 5f125986-4297-4a9d-b36f-79911b213a65
      responses:
        '200':
          description: The requested message schedule
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduledMessageResponse'
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 400
                error: BAD_REQUEST
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Bad Request
                detail: Bad Request message details.
        '401':
          description: Unauthorized Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 401
                error: UNAUTHENTICATED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Unauthorized
                detail: Access to the requested resource lacks valid authentication
                  credentials.
        '403':
          description: Forbidden Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 403
                error: PERMISSION_DENIED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Forbidden
                detail: Access to the requested resource was denied.
        '404':
          description: Schedule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 404
                error: NOT_FOUND
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Not Found
                detail: The HTTP method was not allowed on this endpoint.
      security:
      - oauth2:
        - schedule_manage
      description: ' <br/> Scope: schedule_manage'
    put:
      tags:
      - Scheduled Message
      summary: Update a specific message schedule
      operationId: updateScheduledMessage
      parameters:
      - name: scheduledMessageId
        in: path
        description: The unique identifier of the message schedule
        required: true
        schema:
          type: string
          description: The unique identifier of the message schedule
          format: uuid
          example: 5f125986-4297-4a9d-b36f-79911b213a65
        example: 5f125986-4297-4a9d-b36f-79911b213a65
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScheduledMessageRequest'
        required: true
      responses:
        '200':
          description: Schedule updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduledMessageResponse'
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 400
                error: BAD_REQUEST
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Bad Request
                detail: Bad Request message details.
        '401':
          description: Unauthorized Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 401
                error: UNAUTHENTICATED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Unauthorized
                detail: Access to the requested resource lacks valid authentication
                  credentials.
        '403':
          description: Forbidden Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 403
                error: PERMISSION_DENIED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Forbidden
                detail: Access to the requested resource was denied.
        '404':
          description: Schedule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 404
                error: NOT_FOUND
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Not Found
                detail: The HTTP method was not allowed on this endpoint.
      security:
      - oauth2:
        - schedule_manage
      description: ' <br/> Scope: schedule_manage'
    delete:
      tags:
      - Scheduled Message
      summary: Delete a specific message schedule
      operationId: deleteScheduledMessage
      parameters:
      - name: scheduledMessageId
        in: path
        description: The unique identifier of the message schedule
        required: true
        schema:
          type: string
          description: The unique identifier of the message schedule
          format: uuid
          example: 5f125986-4297-4a9d-b36f-79911b213a65
        example: 5f125986-4297-4a9d-b36f-79911b213a65
      responses:
        '204':
          description: Schedule deleted successfully
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 400
                error: BAD_REQUEST
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Bad Request
                detail: Bad Request message details.
        '401':
          description: Unauthorized Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 401
                error: UNAUTHENTICATED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Unauthorized
                detail: Access to the requested resource lacks valid authentication
                  credentials.
        '403':
          description: Forbidden Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 403
                error: PERMISSION_DENIED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Forbidden
                detail: Access to the requested resource was denied.
        '404':
          description: Schedule not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 404
                error: NOT_FOUND
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Not Found
                detail: The HTTP method was not allowed on this endpoint.
      security:
      - oauth2:
        - schedule_manage
      description: ' <br/> Scope: schedule_manage'
  /v1/scheduledMessages:
    get:
      tags:
      - Scheduled Message
      summary: Retrieves a list of all scheduled messages
      operationId: listScheduledMessages
      responses:
        '200':
          description: A list of scheduled messages
          content:
            application/x-ndjson:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ScheduledMessageResponse'
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduledMessageResponseList'
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 400
                error: BAD_REQUEST
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Bad Request
                detail: Bad Request message details.
        '401':
          description: Unauthorized Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 401
                error: UNAUTHENTICATED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Unauthorized
                detail: Access to the requested resource lacks valid authentication
                  credentials.
        '403':
          description: Forbidden Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 403
                error: PERMISSION_DENIED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Forbidden
                detail: Access to the requested resource was denied.
      security:
      - oauth2:
        - schedule_manage
      description: ' <br/> Scope: schedule_manage'
    post:
      tags:
      - Scheduled Message
      summary: Create a new message schedule
      operationId: createScheduledMessage
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScheduledMessageRequest'
        required: true
      responses:
        '201':
          description: Schedule created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduledMessageResponse'
        '400':
          description: Invalid Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 400
                error: BAD_REQUEST
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Bad Request
                detail: Bad Request message details.
        '401':
          description: Unauthorized Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 401
                error: UNAUTHENTICATED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Unauthorized
                detail: Access to the requested resource lacks valid authentication
                  credentials.
        '403':
          description: Forbidden Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorProblemDetail'
              example:
                status: 403
                error: PERMISSION_DENIED
                requestId: a78150d2-7913-4ea6-933f-286cadac6745
                timestamp: 2018-08-27T12:34:50Z
                type: about:blank
                title: Forbidden
                detail: Access to the requested resource was denied.
      security:
      - oauth2:
        - schedule_manage
      description: ' <br/> Scope: schedule_manage'
components:
  schemas:
    ScheduledMessageRequest:
      required:
      - crontab
      - message
      type: object
      properties:
        message:
          type: object
        crontab:
          pattern: ^([*0-9,-/]+ ){4}[*0-9,-/]+$
          type: string
          description: Schedule as a crontab expression specifying when the message
            should be sent
          example: 0 9 * * *
      description: The path, type and size of the representation to create or update.
      example:
        message:
          category: Document
          type: DocumentCreated
          data:
            relatedDocumentId: bb23bbff-7326-462f-80bc-4a3c5d66567e
        crontab: 0 9 * * *
    ApiErrorProblemDetail:
      required:
      - error
      - requestId
      - timestamp
      type: object
      properties:
        status:
          type: integer
          format: int32
        error:
          type: string
        requestId:
          type: string
        timestamp:
          type: string
          format: date-time
        type:
          type: string
          format: uri
        title:
          type: string
        detail:
          type: string
        instance:
          type: string
          format: uri
        problems:
          type: array
          items:
            $ref: '#/components/schemas/NestedProblem'
        properties:
          type: object
          additionalProperties:
            type: object
    NestedProblem:
      required:
      - detail
      - error
      - title
      type: object
      properties:
        error:
          type: string
        title:
          type: string
        detail:
          type: string
        type:
          type: string
          format: uri
    ScheduledMessageResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the schedule
          format: uuid
          example: 5f125986-4297-4a9d-b36f-79911b213a65
        message:
          type: object
        crontab:
          type: string
          description: Schedule as a crontab expression specifying when the message
            should be sent
          example: 0 9 * * *
      description: The path, type and size of the representation to create or update.
      example:
        message:
          category: Document
          type: DocumentCreated
          data:
            relatedDocumentId: bb23bbff-7326-462f-80bc-4a3c5d66567e
        crontab: 0 9 * * *
    ScheduledMessageResponseList:
      type: object
      properties:
        scheduledMessages:
          type: array
          items:
            $ref: '#/components/schemas/ScheduledMessageResponse'
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: https://api.btx.fr.banqup.com/oauth2/client_credential/gettoken
          scopes:
            info: Scopes are endpoint-specific, see each endpoint for required scope.
        authorizationCode:
          authorizationUrl: https://api.btx.fr.banqup.com/oauth2/auth
          tokenUrl: https://api.btx.fr.banqup.com/oauth2/token
          scopes:
            info: Scopes are endpoint-specific, see each endpoint for required scope.
