openapi: 3.1.0
info:
  title: Tango AP Outbound API
  version: "1.4"
  description: |
    Async REST API for retrieving approved lease payments from Tango. Two-call
    pattern: GET initiating call returns a gu_id; GET /v1/batch/status with the
    gu_id (and optional page_no) returns paginated payment records. The same
    gu_id may be polled multiple times.

    `pay_id` in this outbound is the same identifier as `lease_payment_id` in
    the AP Inbound confirmation payload — reconciliation key.
  x-direction: outbound
  x-source: Tango
  x-destination: Client System
servers:
  - url: https://api.tangoanalytics.com
    description: Production
  - url: https://testapi.tangoanalytics.com
    description: Test (SIT/UAT)
tags:
  - name: AP Payments
  - name: Status
paths:
  /v1/leasemgmt/payments:
    get:
      summary: Initiate approved payment export (async)
      operationId: getAPPaymentsBatch
      tags: [AP Payments]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: calendar_year
          required: false
          schema: { type: integer }
          description: 4-digit fiscal year (YYYY).
        - in: query
          name: calendar_month
          required: false
          schema: { type: integer, minimum: 1, maximum: 12 }
          description: Fiscal period.
        - in: query
          name: country
          required: false
          schema: { type: string }
          description: 3-digit country code.
        - in: query
          name: financial_group
          required: false
          schema: { type: string }
      responses:
        "200":
          description: Async ack with gu_id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Retrieve paginated payment records by gu_id
      operationId: getAPPaymentsByGuId
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema: { type: string, format: uuid }
        - in: query
          name: page_no
          required: false
          schema: { type: integer, minimum: 1 }
      responses:
        "200":
          description: Paginated payment records.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PaymentPage"
components:
  securitySchemes:
    xClientHeader: { type: apiKey, in: header, name: x-client }
    xApiKeyHeader: { type: apiKey, in: header, name: x-api-key }
  parameters:
    XClient:
      name: x-client
      in: header
      required: true
      schema: { type: string }
    XApiKey:
      name: x-api-key
      in: header
      required: true
      schema: { type: string }
  schemas:
    AcceptedResponse:
      type: object
      required: [status]
      properties:
        status: { type: string, enum: [OK, Error] }
        status_message: { type: string }
        gu_id: { type: string, format: uuid }
    PaymentPage:
      type: object
      required: [status, total_records, total_pages, page_size, page_no, records]
      properties:
        status: { type: string, enum: [PROCESSING, COMPLETED, ERROR] }
        total_records: { type: integer }
        total_pages: { type: integer }
        page_size: { type: integer, default: 5000 }
        page_no: { type: integer }
        records:
          type: array
          items:
            $ref: "#/components/schemas/PaymentRecord"
    PaymentRecord:
      type: object
      description: |
        Lease payment record. Required fields per the doc; null fields are
        omitted from the JSON entirely.
      required:
        - pay_id
        - lease_num
        - status
        - term_status
        - loc_num
        - year
        - mon
        - ven_num
        - category
        - type
        - effective_date
        - applies_from_date
        - applies_to_date
      properties:
        pay_id:
          type: number
          description: Tango unique payment ID (same as lease_payment_id in AP Inbound).
        lease_num: { type: string }
        status: { type: string, description: "Lease status." }
        term_status: { type: string }
        loc_num: { type: string }
        year:
          type: integer
          description: Fiscal year (not calendar year).
        mon:
          type: integer
          description: Fiscal period (not calendar month).
        ven_num: { type: string, description: "Vendor number." }
        comments: { type: string }
        sys_gen_flag: { type: string }
        category: { type: string }
        type: { type: string }
        effective_date: { type: string, description: "MM/DD/YYYY." }
        applies_from_date: { type: string, description: "MM/DD/YYYY." }
        applies_to_date: { type: string, description: "MM/DD/YYYY." }
        due_date: { type: string, description: "MM/DD/YYYY." }
        creation_date: { type: string, description: "MM/DD/YYYY." }
        gross: { type: number }
        tax1: { type: number }
        tax2: { type: number }
        total_tax: { type: number }
        net: { type: number }
        pay_status: { type: string }
        tax_rate: { type: string }
        currency: { type: string }
        pay_currency: { type: string }
        consumption: { type: string }
        consum_uom: { type: string }
        account_string: { type: string }
        inv_num: { type: string }
        inv_id: { type: string }
        remit_message: { type: string }
        gl_acc: { type: string }
        country: { type: string }
        legal_entity: { type: string }
        seg1: { type: string }
        seg2: { type: string }
        seg3: { type: string }
        seg4: { type: string }
        seg5: { type: string }
        seg6: { type: string }
        seg1_gl: { type: string }
        seg2_gl: { type: string }
        seg3_gl: { type: string }
        seg4_gl: { type: string }
        seg5_gl: { type: string }
        seg6_gl: { type: string }
        cattr1: { type: string }
        cattr2: { type: string }
        cattr3: { type: string }
        cattr4: { type: string }
        cattr5: { type: string }
        cattr6: { type: string }
        cattr7: { type: string }
        cattr8: { type: string }
        cattr9: { type: string }
        cattr10: { type: string }
        cattr11: { type: string }
        cattr12: { type: string }
        cattr13: { type: string }
        cattr14: { type: string }
        cattr15: { type: string }
        cattr16: { type: string }
        payext2: { type: string }
        payext3: { type: string }
        payext4: { type: string }
        payext5: { type: string }
        payext6: { type: string }
        payext7: { type: string }
        payext8: { type: string }
        supplier_number: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
