---
openapi: 3.0.0
info:
  title: Paystubs Webhooks API
  version: 1.0.0
  description: |
    API for managing Paystubs webhooks.
    Sent when paystubs are added or updated.

    If you need to access to paystubs as soon as they are available:

    *   The `paystubs.partially_synced` webhook is sent when paystubs going back a specified number of days prior (starting from the date when the account was added) have been retrieved during initial data retrieval for a newly connected account.
    *   The `paystubs.fully_synced` webhook is sent when all paystubs have been retrieved during initial data retrieval for a newly connected account.
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 `paystubs.added` webhook is sent only when an account''s data is [refreshed](/overview/ongoing-refresh) (does not include initial data retrieval) and a new paystub is retrieved.

'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              "$ref": "#/components/schemas/PaystubsAddedSubscriptionRequest"
            examples:
              paystubs_added_subscription:
                summary: paystubs.added subscription
                value:
                  events:
                  - paystubs.added
                  name: name-for-the-webhook-subscription
                  url: https://your-webhook-backend.com
                  secret: optional-secret
      responses:
        '200':
          description: Successful subscription
          content:
            application/json:
              schema:
                type: object
                properties:
                  event:
                    type: string
                    enum:
                    - paystubs.added
                    description: The type of event being triggered.
                  name:
                    type: string
                    description: The name of the webhook subscription.
                  data:
                    type: object
                    properties:
                      account:
                        type: string
                        format: uuid
                        description: The unique identifier of the account.
                      user:
                        type: string
                        format: uuid
                        description: The unique identifier of the user associated with the paystubs.
                      available_from:
                        type: string
                        format: date-time
                        description: The timestamp when paystubs became available.
                      available_to:
                        type: string
                        format: date-time
                        description: The timestamp until when paystubs are available.
                      available_count:
                        type: integer
                        description: The total number of available paystubs.
                      added_count:
                        type: integer
                        description: The number of newly added paystubs.
                      added_from:
                        type: string
                        format: date-time
                        description: The timestamp from which the newly added paystubs are available.
                      added_to:
                        type: string
                        format: date-time
                        description: The timestamp until which the newly added paystubs are available.
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Error message
components:
  securitySchemes:
    basicAuth:
      type: http
      scheme: basic
      description: Username = api_key_id, Password = api_key_secret
  schemas:
    PaystubsAddedSubscriptionRequest:
      type: object
      description: Request body for subscribing to the `paystubs.added` webhook.
      properties:
        events:
          type: array
          items:
            type: string
            enum:
            - paystubs.added
          description: |
            List of events to subscribe to. Must include `paystubs.added`.
            Value is `paystubs.added`
        name:
          type: string
          description: |
            Your name for the webhook subscription.
            Name used 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.
            URL where you want to receive webhook delivery.
        secret:
          type: string
          nullable: true
          description: |
            Optional secret used to verify webhooks.
            Secret used to verify webhooks.
      required:
      - events
      - name
      - url
      example:
        events:
        - paystubs.added
        name: name-for-the-webhook-subscription
        url: https://your-webhook-backend.com
        secret: optional-secret
    PaystubsUpdatedSubscriptionRequest:
      type: object
      description: Request body for subscribing to the `paystubs.updated` webhook.
      properties:
        events:
          type: array
          items:
            type: string
            enum:
            - paystubs.updated
          description: |
            List of events to subscribe to. Must include `paystubs.updated`.
            Value is `paystubs.updated`
        name:
          type: string
          description: |
            Your name for the webhook subscription.
            Name used 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.
            URL where you want to receive webhook delivery.
        secret:
          type: string
          nullable: true
          description: |
            Optional secret used to verify webhooks.
            Secret used to verify webhooks.
      required:
      - events
      - name
      - url
    PaystubsPartiallySyncedSubscriptionRequest:
      type: object
      description: Request body for subscribing to the `paystubs.partially_synced` webhook.
      properties:
        events:
          type: array
          items:
            type: string
            enum:
            - paystubs.partially_synced
          description: |
            List of events to subscribe to. Must include `paystubs.partially_synced`.
            Value is `paystubs.partially_synced`
        name:
          type: string
          description: |
            Your name for the webhook subscription.
            Name used 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.
            URL where you want to receive webhook delivery.
        secret:
          type: string
          nullable: true
          description: |
            Optional secret used to verify webhooks.
            Secret used to verify webhooks.
        config:
          type: object
          nullable: true
          description: |
            `"days_synced": <Integer>` specifies how many days of paystub history must be synced, counted backward from `account.created_at`, before the webhook is sent.
          properties:
            days_synced:
              type: integer
      required:
      - events
      - name
      - url
    PaystubsFullySyncedSubscriptionRequest:
      type: object
      description: Request body for subscribing to the `paystubs.fully_synced` webhook.
      properties:
        events:
          type: array
          items:
            type: string
            enum:
            - paystubs.fully_synced
          description: |
            List of events to subscribe to. Must include `paystubs.fully_synced`.
            Value is `paystubs.fully_synced`
        name:
          type: string
          description: |
            Your name for the webhook subscription.
            Name used 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.
            URL where you want to receive webhook delivery.
        secret:
          type: string
          nullable: true
          description: |
            Optional secret used to verify webhooks.
            Secret used to verify webhooks.
      required:
      - events
      - name
      - url
