openapi: 3.0.0
info:
  title: Reports Webhooks API
  version: "1.0.0"
  description: |
    Sent when reports can be or have been generated.

servers:
  - url: https://api-sandbox.argyle.com
    description: Sandbox
  - url: https://api.argyle.com
    description: Production
security:
  - basicAuth: []

paths:
  /v2/webhooks:
    post:
      summary: Example subscription
      description: |
        The `reports.ready` webhook is sent when a [verification report](/api-reference/reports) can be generated once sufficient data has been retrieved from a connected payroll account.

        The `reports.ready` webhook is also sent after an [account reconnection](/workflows/reconnecting-accounts) once all new data has been retrieved.

        <Info>
        This webhooks may be sent multiple times if the user connects multiple accounts.
        - The [accounts.connected](/api-reference/accounts-webhooks/connected) and [accounts.failed](/api-reference/accounts-webhooks/failed) webhooks can be used to track multiple account connections.
        - Compare them to the accounts listed in the reports.ready webhook payload to determine when to generate a report.
        </Info>
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReportsReadyRequest'
            examples:
              reports_ready_subscription:
                summary: reports.ready subscription
                value:
                  events:
                  - reports.ready
                  name: name-for-the-webhook-subscription
                  url: https://your-webhook-backend.com
                  secret: optional-secret
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReportsReadyWebhookMessage'
              examples:
                reports_ready:
                  summary: Example Reports Ready
                  value:
                    event: "reports.ready"
                    name: "name-for-the-webhook-subscription"
                    data:
                      user: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
                      resource:
                        user: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
                        external_id: ""
                        accounts:
                          - id: "0185a8b8-60eb-80ca-7482-5f24504573f7"
                            last_synced_at: "2024-01-08T12:55:04.016059Z"
                          - id: "0187c66e-e7e5-811c-b006-2232f00f426a"
                            last_synced_at: "2024-01-08T12:58:06.023659Z"
                        documents: []
                reports_generated:
                  summary: Example Reports Generated
                  value:
                    event: "reports.generated"
                    name: "name-for-the-webhook-subscription"
                    data:
                      user: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
                      type: "voie"
                      report_id: "43a2c6c3-1e63-91e5-88e3-f9ab2dcc489b"

  # /v2/webhooks:
  #   post:
  #     summary: Generated
  #     description: |
  #       The `reports.generated` webhook is sent when a report has been successfully [generated](/api-reference/reports#generate) and can be retrieved.
  #     requestBody:
  #       required: true
  #       content:
  #         application/json:
  #           schema:
  #             $ref: '#/components/schemas/ReportsGeneratedRequest'
  #     responses:
  #       '200':
  #         description: Success
  #         content:
  #           application/json:
  #             schema:
  #               $ref: '#/components/schemas/ReportsGeneratedWebhookMessage'
  #             example:
  #               event: "reports.generated"
  #               name: "name-for-the-webhook-subscription"
  #               data:
  #                 user: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
  #                 type: "voie"
  #                 report_id: "43a2c6c3-1e63-91e5-88e3-f9ab2dcc489b"

components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Username = api_key_id, Password = api_key_secret
  schemas:
    ReportsReadyRequest:
      type: object
      properties:
        events:
          type: array
          description: "`reports.ready`"
          items:
            type: string
          example: ["reports.ready"]
        name:
          type: string
          description: "Your name for the webhook subscription."
          example: "My Webhook"
        url:
          type: string
          description: Where you want to receive webhook delivery. This can be either a backend URL that you manage, or a URL provided by a webhook management service. Argyle handles URL encoding for webhook URLs. Send the URL in its normal, unencoded form.
          example: "https://your-webhook-backend.com"
        secret:
          type: string
          description: "Optional secret used to [verify webhooks](/api-guide/webhooks#verifying-webhooks)."
          example: "your-secret-key"
      required:
        - events
        - name
        - url
      example:
        events:
        - reports.ready
        name: name-for-the-webhook-subscription
        url: https://your-webhook-backend.com
        secret: optional-secret

    ReportsGeneratedRequest:
      type: object
      properties:
        events:
          type: array
          description: "`reports.generated`"
          items:
            type: string
          example: ["reports.generated"]
        name:
          type: string
          description: "Your name for the webhook subscription."
          example: "My Webhook"
        url:
          type: string
          description: Where you want to receive webhook delivery. This can be either a backend URL that you manage, or a URL provided by a webhook management service. Argyle handles URL encoding for webhook URLs. Send the URL in its normal, unencoded form.
          example: "https://your-webhook-backend.com"
        secret:
          type: string
          description: "Optional secret used to [verify webhooks](/api-guide/webhooks#verifying-webhooks)."
          example: "your-secret-key"
      required:
        - events
        - name
        - url

    ReportsReadyWebhookMessage:
      type: object
      properties:
        event:
          type: string
          description: "`reports.ready`"
          example: "reports.ready"
        name:
          type: string
          description: "Name used for the webhook subscription."
          example: "My Webhook"
        data:
          type: object
          properties:
            user:
              type: string
              format: uuid
              description: "ID of the user."
              example: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
            resource:
              type: object
              description: Related resources available for report generation.
              properties:
                user:
                  type: string
                  format: uuid
                  description: "ID of the user."
                  example: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
                external_id:
                  type: string
                  nullable: true
                  description: "The [external_id](/api-reference/users#object-external_id) of the user, otherwise `null`."
                  example: ""
                accounts:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                        format: uuid
                        description: "ID of the account."
                        example: "0185a8b8-60eb-80ca-7482-5f24504573f7"
                      last_synced_at:
                        type: string
                        format: date-time
                        description: "Timestamp ([ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)) when the account was last scanned for new data."
                        example: "2024-01-08T12:55:04.016059Z"
                documents:
                  type: array
                  description: "Documents available for report generation."
                  items:
                    type: object

    ReportsGeneratedWebhookMessage:
      type: object
      properties:
        event:
          type: string
          description: "`reports.generated`"
          example: "reports.generated"
        name:
          type: string
          description: "Name used for the webhook subscription."
          example: "My Webhook"
        data:
          type: object
          properties:
            user:
              type: string
              format: uuid
              description: "ID of the user."
              example: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
            type:
              type: string
              description: "The [type](/api-reference/reports#object-type) of report."
              example: "voie"
            report_id:
              type: string
              format: uuid
              description: "ID of the report."
              example: "43a2c6c3-1e63-91e5-88e3-f9ab2dcc489b"
