openapi: 3.0.3
info:
  title: Everflow Network API - Webhooks
  description: Endpoints for managing webhook configurations in the Everflow network.
  version: 1.0.0
servers:
  - description: Production Server
    url: https://api.eflow.team/v1
tags:
  - name: Webhooks
    description: Endpoints for managing webhooks.
paths:
  /networks/webhooks/{webhookId}:
    get:
      summary: Get Webhook Config
      tags:
        - Webhooks
      parameters:
        - in: path
          name: webhookId
          required: true
          schema:
            type: integer
          description: The webhook ID.
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Webhook"
      security:
        - API Key: []
    put:
      summary: Update Webhook
      tags:
        - Webhooks
      parameters:
        - in: path
          name: webhookId
          required: true
          schema:
            type: integer
          description: The webhook ID.
      requestBody:
        required: true
        content:
          application/json:
            example:
              webhook_types:
                - "affiliate_updated"
              http_method: "post"
              webhook_url: "https://example.com/webhook"
              description: "Updated webhook"
              status: "active"
            schema:
              type: object
              required:
                - webhook_types
                - http_method
                - webhook_url
                - status
                - description
              properties:
                webhook_types:
                  type: array
                  items:
                    type: string
                    enum:
                      - advertiser_created
                      - advertiser_signed_up
                      - advertiser_updated
                      - affiliate_approved_for_offer
                      - affiliate_created
                      - affiliate_signed_up
                      - affiliate_signup_verdict
                      - affiliate_updated
                      - offer_created
                      - offer_updated
                      - traffic_optimized
                  description: >
                    Event types that should trigger this webhook. You can
                    specify more than one.
                http_method:
                  type: string
                  enum:
                    - get
                    - post
                  description: HTTP method to use when sending the webhook.
                webhook_url:
                  type: string
                  description: The webhook endpoint URL.
                description:
                  type: string
                  description: Name or description for the webhook.
                status:
                  type: string
                  enum:
                    - active
                    - inactive
                  description: Webhook status.
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Webhook"
      security:
        - API Key: []
    delete:
      summary: Delete Webhook
      description: >
        Permanently delete a webhook configuration by its ID.
      tags:
        - Webhooks
      parameters:
        - in: path
          name: webhookId
          required: true
          schema:
            type: integer
          description: The webhook ID.
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                type: object
                properties:
                  result:
                    type: boolean
                    description: Whether the deletion was successful.
      security:
        - API Key: []

  /networks/webhooks:
    post:
      summary: Create Webhook
      tags:
        - Webhooks
      requestBody:
        required: true
        content:
          application/json:
            example:
              webhook_types:
                - "affiliate_updated"
              http_method: "post"
              webhook_url: "https://example.com/webhook"
              description: "My webhook"
              status: "active"
            schema:
              type: object
              required:
                - webhook_types
                - http_method
                - webhook_url
                - status
                - description
              properties:
                webhook_types:
                  type: array
                  items:
                    type: string
                    enum:
                      - advertiser_created
                      - advertiser_signed_up
                      - advertiser_updated
                      - affiliate_approved_for_offer
                      - affiliate_created
                      - affiliate_signed_up
                      - affiliate_signup_verdict
                      - affiliate_updated
                      - offer_created
                      - offer_updated
                      - traffic_optimized
                  description: >
                    Event types that should trigger this webhook. You can
                    specify more than one.
                http_method:
                  type: string
                  enum:
                    - get
                    - post
                  description: HTTP method to use when sending the webhook.
                webhook_url:
                  type: string
                  description: The webhook endpoint URL.
                description:
                  type: string
                  description: Name or description for the webhook.
                status:
                  type: string
                  enum:
                    - active
                    - inactive
                  description: Webhook status.
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Webhook"
      security:
        - API Key: []

  /networks/webhooks/{webhookId}/logs:
    get:
      summary: Get Webhook Delivery Logs
      tags:
        - Webhooks
      parameters:
        - in: path
          name: webhookId
          required: true
          schema:
            type: integer
          description: The webhook ID.
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                type: object
                properties:
                  logs:
                    type: array
                    items:
                      $ref: "#/components/schemas/WebhookLog"
      security:
        - API Key: []

components:
  schemas:
    Webhook:
      type: object
      description: A webhook configuration.
      properties:
        network_webhook_id:
          type: integer
          example: 1
          description: Unique webhook ID.
        network_id:
          type: integer
          example: 1
          description: Network ID.
        webhook_types:
          type: array
          example:
            - "affiliate_updated"
          items:
            type: string
            enum:
              - advertiser_created
              - advertiser_signed_up
              - advertiser_updated
              - affiliate_approved_for_offer
              - affiliate_created
              - affiliate_signed_up
              - affiliate_signup_verdict
              - affiliate_updated
              - offer_created
              - offer_updated
              - traffic_optimized
          description: Event types that trigger this webhook.
        http_method:
          type: string
          example: "post"
          enum:
            - get
            - post
          description: HTTP method used when sending the webhook.
        webhook_url:
          type: string
          example: "https://example.com/webhook"
          description: The webhook endpoint URL.
        description:
          type: string
          example: "My webhook"
          description: Optional description for the webhook.
        status:
          type: string
          example: "active"
          enum:
            - active
            - inactive
          description: Webhook status.
        time_created:
          type: integer
          example: 1774726693
          description: Unix timestamp of creation.
        time_saved:
          type: integer
          example: 1774726693
          description: Unix timestamp of last update.
    WebhookLog:
      type: object
      description: A webhook delivery log entry.
      properties:
        network_webhook_log_id:
          type: integer
          example: 5801398
          description: Unique log entry ID.
        network_webhook_id:
          type: integer
          example: 50
          description: The webhook ID this log belongs to.
        network_id:
          type: integer
          example: 1
          description: Network ID.
        unix_timestamp:
          type: integer
          example: 1774638805
          description: Unix timestamp of the delivery attempt.
        webhook_url:
          type: string
          example: "https://example.com/webhook"
          description: The URL the webhook was sent to.
        http_method:
          type: string
          example: "post"
          enum:
            - get
            - post
          description: HTTP method used for the delivery.
        payload:
          type: string
          example: "{\"network_affiliate_id\":123,\"name\":\"Example Partner\"}"
          description: >
            JSON-encoded string of the event payload that was sent to the
            webhook URL.
        response_code:
          type: integer
          example: 200
          description: HTTP response status code returned by the webhook URL.
        debug_information:
          type: string
          example: "Source : Webhook 50 (network 1) with target URL https://example.com/webhook. Event : AFFILIATE_UPDATED (object AFFILIATE ID 123)."
          description: >
            Debug details including the event type, object ID, retry count,
            and response headers.
        is_success:
          type: boolean
          example: true
          description: Whether the delivery was successful.
  securitySchemes:
    API Key:
      description: The Everflow API key generated from the Control Center > Security.
      in: header
      name: X-Eflow-Api-Key
      type: apiKey
