openapi: 3.0.0
info:
  title: User Forms Webhooks API
  version: "1.0.0"
  description: |
    API definition for User Forms Webhooks.
    Sent when [user form](/api-reference/user-forms#object) events occur.

    User forms are response forms (see [Step 4](/workflows/account-connections#search)) that users can submit as a fallback when they cannot find their employer or payroll provider.

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 `user_forms.submitted` webhook is sent when a response form is submitted.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionRequest'
            examples:
              user_forms_submitted_subscription:
                summary: user_forms.submitted subscription
                value:
                  events:
                  - user_forms.submitted
                  name: name-for-the-webhook-subscription
                  url: https://your-webhook-backend.com
                  secret: optional-secret

      responses:
        '200':
          description: Webhook subscription successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WebhookMessageSubmitted'
  # /v2/webhooks:
  #   post:
  #     summary: Removed
  #     description: |
  #       The `user_forms.removed` webhook is only sent when an account is deleted.
  #     requestBody:
  #       content:
  #         application/json:
  #           schema:
  #             oneOf:
  #               - $ref: '#/components/schemas/SubscriptionRequestRemoved'
  #               - $ref: '#/components/schemas/SubscriptionRequestRemoved'
  #     responses:
  #       '200':
  #         description: Webhook subscription successful
  #         content:
  #           application/json:
  #             schema:
  #               $ref: '#/components/schemas/WebhookMessageRemoved'

components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Username = api_key_id, Password = api_key_secret
  schemas:
    SubscriptionRequest:
      type: object
      properties:
        events:
          type: array
          description: "`user_forms.submitted`"
          items:
            type: string
          example: ["user_forms.submitted"]
        name:
          type: string
          description: "Your name for the webhook subscription."
          example: "name-for-the-webhook-subscription"
        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: "optional-secret"
      required:
        - events
        - name
        - url
      example:
        events:
        - user_forms.submitted
        name: name-for-the-webhook-subscription
        url: https://your-webhook-backend.com
        secret: optional-secret
    SubscriptionRequestRemoved:
      type: object
      properties:
        events:
          type: array
          description: "`user_forms.removed`"
          items:
            type: string
          example: ["user_forms.removed"]
        name:
          type: string
          description: "Your name for the webhook subscription."
          example: "name-for-the-webhook-subscription"
        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: "optional-secret"
      required:
        - events
        - name
        - url
    WebhookMessageSubmitted:
      type: object
      properties:
        event:
          type: string
          description: "`user_forms.submitted`"
          example: "user_forms.submitted"
        name:
          type: string
          description: "Name used for the webhook subscription."
          example: "name-for-the-webhook-subscription"
        data:
          type: object
          properties:
            account:
              type: string
              format: uuid
              description: "ID of the account."
              example: "01856c65-43b6-8b5d-b32a-56b8fbda5c28"
            user:
              type: string
              format: uuid
              description: "ID of the user."
              example: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
            user_form:
              type: string
              format: uuid
              description: "ID of the user form."
              example: "0187bf23-cd80-118d-c0b8-58023e21c8e5"
    WebhookMessageRemoved:
      type: object
      properties:
        event:
          type: string
          description: "`user_forms.removed`"
          example: "user_forms.removed"
        name:
          type: string
          description: "Name used for the webhook subscription."
          example: "name-for-the-webhook-subscription"
        data:
          type: object
          properties:
            account:
              type: string
              format: uuid
              description: "ID of the account."
              example: "01856c65-43b6-8b5d-b32a-56b8fbda5c28"
            user:
              type: string
              format: uuid
              description: "ID of the user."
              example: "018051aa-f7a9-a0db-2f38-6cfa325e9d69"
            user_form:
              type: string
              format: uuid
              description: "ID of the user form."
              example: "0187bf23-cd80-118d-c0b8-58023e21c8e5"
