openapi: 3.0.0
info:
  title: Reports API
  contact:
    name: API Integration Support
    email: integration@dintero.com
  description: |
    # Changelog
    All notable changes to the API.

    ## 2021-12-01

    > Updated returned report metadata to reflect the additional data stored pr. report

    ## 2021-09-23

    > Removed not implemented endpoint from spec \
    > Added admin:reports scope to endpoints

    ## 2021-08-31

    > Added new endpoint for fetching reports metadata
    > - [GET /v1/accounts/{aid}/reports/metadata](/reports-api/reports/api_reports_metadata_list_get)

    ## 2021-08-26

    > Removed not implemented endpoint from spec \
    > Added new save flag for persisting reports \
    > Added new response for when the save flag is used to persist reports
  version: LATEST
  license:
    name: UNLICENSED
    url: https://dintero.com
  x-logo:
    url: https://docs.dintero.com/img/dintero-dark-padded.svg
    altText: Dintero Logo
security:
  - JWT: []
paths:
  /accounts/{aid}/reports/generation:
    post:
      operationId: api_reports_generation_post
      summary: api_reports_generation_post
      description: |
        Using this endpoint with the query parameter **save** set to true, will result in an **201**
        response, otherwise, the response will be **200**.

        #### Generate PDF report for transaction:

        First, fetch the transaction from [Get transaction](/api-reference/transactions/transactions_id_get).

        Store the transaction in the `transaction` variable and send this payload:

            [
              {
                "key": "transaction",
                "path": "/checkout/v1/transactions/{transaction.id}",
                "data": transaction
              }
            ]

        with these query parameters set:

        - template_id=checkout_transaction_order
        - template_data_path=/checkout/v1/transactions/{transaction.id}
        - template_accept=application/pdf
        - template_accept_language=en

        **scopes**:
          - admin:reports
          - write:reports
          - read:reports
      x-scopes:
        - admin:reports
        - write:reports
        - read:reports
      tags:
        - reports
      parameters:
        - $ref: '#/components/parameters/accountId'
        - name: template_id
          in: query
          required: true
          description: |
            The template to generate report from

            example:
              - checkout_transaction_order
          schema:
            type: string
        - name: template_data_path
          in: query
          required: true
          description: |
            Path to the data for the report

            examples:
              - /checkout/v1/transactions/{transaction.id}
          schema:
            type: string
        - name: template_accept
          in: query
          required: true
          description: |
            The Content-Type for the report

            examples:
              - application/pdf
          schema:
            type: string
        - name: template_accept_language
          in: query
          required: true
          description: |
            The Content-Language for the report

            examples:
              - no
              - en
          schema:
            type: string
        - name: template_accept_timezone
          in: query
          required: false
          description: |
            The timezone for the report
            List of timezones: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
            Defaults to Europe/Oslo

            examples:
              - Europe/Stockholm
              - Europe/London
              - Europe/Helsinki
          schema:
            type: string
            format: iana-timezone
        - name: data_from
          in: query
          description: |
            The start of the data interval
          required: false
          schema:
            type: string
            format: date-time
        - name: data_to
          in: query
          description: |
            The end of the data interval
          required: false
          schema:
            type: string
            format: date-time
        - name: schedule
          in: query
          description: Schedule for the report
          required: false
          schema:
            type: string
            enum:
              - monthly
              - weekly
              - daily
              - custom
              - none
        - name: save
          in: query
          required: false
          description: Whether to save the generated report in s3 or not, if set to true returns **201**
          schema:
            type: boolean
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                type: object
                required:
                  - key
                  - path
                  - data
                properties:
                  key:
                    type: string
                  path:
                    type: string
                  data:
                    type: object
        required: true
      responses:
        '200':
          $ref: '#/components/responses/ReportFile'
        '201':
          $ref: '#/components/responses/SignedUrl'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/ServerError'
      x-mint:
        metadata:
          title: Generate report from data
          sidebarTitle: Generate report from data
  /accounts/{aid}/reports/metadata:
    get:
      operationId: api_reports_metadata_list_get
      summary: api_reports_metadata_list_get
      description: |
        Get list of report metadata for the account

        Scopes:
          - read:reports
          - admin:reports
      x-scopes:
        - read:reports
        - admin:reports
      tags:
        - reports
      parameters:
        - $ref: '#/components/parameters/accountId'
        - $ref: '#/components/parameters/limit'
        - $ref: '#/components/parameters/startingAfter'
      responses:
        '200':
          $ref: '#/components/responses/ReportMetadata'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/ServerError'
      servers:
        - url: https://api.dintero.com/v1
      x-mint:
        metadata:
          title: List report metadata
          sidebarTitle: List report metadata
servers:
  - url: https://api.dintero.com/v1
components:
  parameters:
    accountId:
      name: aid
      description: |
        An id that uniquely identifies the account.
      in: path
      required: true
      schema:
        type: string
        format: ^[PT]{1}\d{8}$
        minLength: 9
        maxLength: 9
    limit:
      name: limit
      in: query
      description: |
        A limit on the number of objects to be returned. Limit can range
        between 1 and 100 items, and the default is 10 items.
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 10
    startingAfter:
      name: starting_after
      in: query
      description: |
        cursor for use in pagination. starting_after is an object ID
        that defines your place in the list. For instance, if you make
        a list request and receive 100 objects, end the result contains
          `paging_token=pt1`, your subsequent call can include
        `starting_after=pt1` in order to fetch the next page of the list.
      required: false
      schema:
        type: string
  responses:
    ReportFile:
      description: Report file
      content:
        application/json:
          schema:
            type: string
    SignedUrl:
      description: SignedUrl
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SignedUrl'
    BadRequest:
      description: Bad / Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ServerError:
      description: Unexpected Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ReportMetadata:
      description: Report Metadata
      content:
        application/json:
          schema:
            properties:
              reports:
                type: array
                items:
                  $ref: '#/components/schemas/ReportMetadata'
              starting_after:
                $ref: '#/components/schemas/StartingAfter'
  securitySchemes:
    JWT:
      type: http
      description: |
        Bearer authentication (token authentication) should be used for accessing the API.

        Use [Get Token](/api-reference/authenticate/aid_auths_oauth_token_post) to get an access token for client credentials.
        Pass the token in the request header:

            Authorization: Bearer {access_token}

        where the **access_token** is JSON Web Tokens (JWT).
      scheme: bearer
      bearerFormat: JWT
  schemas:
    SignedUrl:
      type: object
      properties:
        signed_url:
          type: string
          description: |
            Signed url used to download the report from s3
        id:
          type: string
          description: Id of the report
        template_id:
          type: string
          description: Id of the template used to create the report
        template_data_path:
          type: string
          description: Path to the resource, if no template is used
          example: /checkout/v1/transactions/{transaction_id}
        content_type:
          type: string
          description: Report content type
          example: application/pdf
        content_language:
          type: string
          description: Report content language
          example: en
        created_by:
          type: string
          example: 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
          description: |
            The ID of the user/client that created the report
          readOnly: true
        created_at:
          type: string
          format: date-time
          description: |
            The date-time when the report was created
          readOnly: true
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
          properties:
            code:
              type: string
              description: The code used to identify the error/warning
            errors:
              type: array
              description: The nested error(s) encountered during validation
              items:
                type: object
            message:
              type: string
              description: The human readable description of the error/warning
    ReportFilter:
      type: object
      properties:
        filter:
          type: string
          enum:
            - operation_payout_destination
            - store_id
          description: The "field/column" the data will be filtered on
        value:
          type: string
          description: The value the records must contain for the provided filter (field/column)
    ReportMetadata:
      type: object
      properties:
        id:
          type: string
          description: Unique identification of the report
          readOnly: true
        report_job_id:
          type: string
          description: Unique identification for all reports created by the same reportconfig at the same time (with different content types)
          readOnly: true
        account_id:
          type: string
          description: Id of the report owner
          readOnly: true
        template_id:
          type: string
          description: Id of the template used to create the report
          readOnly: true
        content_type:
          type: string
          description: Report content type
          example: application/pdf
          readOnly: true
        content_language:
          type: string
          description: Report content language
          example: en
          readOnly: true
        created_by:
          type: string
          example: 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
          description: |
            The ID of the user/client that created the report
          readOnly: true
        created_at:
          type: string
          format: date-time
          description: |
            The date-time when the report was created
          readOnly: true
        data_from:
          type: string
          format: date-time
          description: |
            The start of the data interval, contains created_at if data_from qparam not provided
          readOnly: true
        data_to:
          type: string
          format: date-time
          description: |
            The end of the data interval, contains created_at if data_to qparam not provided
          readOnly: true
        schedule:
          type: string
          description: Schedule for the report
          readOnly: true
        report_file_name:
          type: string
          description: |
            Name of the report file stored in S3.
          readOnly: true
        custom_report_name:
          type: string
          description: |
            Custom name of the report, defined in the report configuration used to generate the report
          readOnly: true
        report_config_id:
          type: string
          description: |
            Id of the report configuration used to generate the report.
          readOnly: true
        data_type:
          type: string
          description: |
            Source of the data used to generate the report. Defined by the report configuration used to create the report
          readOnly: true
        signed_url:
          type: string
          description: |
            Signed url used to download the report from s3
          readOnly: true
        report_filters:
          type: array
          description: List of filters used to filter the data for the report. Similar to SQL WHERE-clause. i.e, WHERE filter=value
          items:
            $ref: '#/components/schemas/ReportFilter'
    StartingAfter:
      type: string
      description: |
        cursor for use in pagination. starting_after is an object ID
        that defines your place in the list. For instance, if you make
        a list request and receive 100 objects, ending with `obj_foo`,
        your subsequent call can include `starting_after=obj_foo`
        in order to fetch the next page of the list.
