openapi: 3.1.0
info:
  title: Tango Lease Invoices Outbound API
  version: "0.3"
  description: |
    Async REST API: client GETs approved lease invoices from Tango. Invoices
    can contain multiple line items (each a payment id); the response groups
    line items under each invoice header. Two-call pattern with gu_id and
    paginated retrieval (5000 records/page). Null fields are omitted.
  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: Lease Invoices
  - name: Status
paths:
  /v1/leasemgmt/invoices:
    get:
      summary: Initiate lease invoice export (async)
      operationId: getLeaseInvoicesBatch
      tags: [Lease Invoices]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: calendar_year
          required: false
          schema: { type: integer }
        - in: query
          name: calendar_month
          required: false
          schema: { type: integer, minimum: 1, maximum: 12 }
        - in: query
          name: country
          required: false
          schema: { type: string }
        - in: query
          name: financial_group
          required: false
          schema: { type: string }
      responses:
        "200":
          description: Async ack.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Retrieve paginated lease invoice records by gu_id
      operationId: getLeaseInvoicesByGuId
      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 invoice records.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InvoicePage"
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 }
    InvoicePage:
      type: object
      required: [total_records, total_pages, page_size, page_no, records]
      properties:
        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/InvoiceHeader"
    InvoiceHeader:
      type: object
      required:
        - invoice_id
        - lease_num
        - loc_num
        - status
        - term_status
        - ven_num
      properties:
        invoice_id:
          type: number
          description: Tango unique invoice ID. Each invoice can have multiple line items.
        lease_num: { type: string }
        loc_num: { type: string }
        legal_entity: { type: string }
        invoice_number: { type: string }
        status: { type: string, description: "Lease status." }
        term_status: { type: string }
        ven_num: { type: string, description: "Vendor number." }
        invoice_date: { type: string, description: "MM/DD/YYYY." }
        invoice_description: { type: string }
        invoice_comments: { type: string }
        invoice_status: { type: string }
        due_date: { type: string, description: "MM/DD/YYYY." }
        creation_date: { type: string, description: "MM/DD/YYYY." }
        currency: { type: string }
        country: { type: string }
        invoice_gross_amount: { type: number }
        invoice_tax_amount: { type: number }
        invoice_net_amount: { type: number }
        exchange_rate: { type: string }
        received_date: { type: string, description: "MM/DD/YYYY." }
        invoice_required: { type: string }
        e_invoice_number: { type: string }
        purchase_order_number: { type: string }
        barcode_number: { type: string }
        net_terms: { type: string }
        irn_number: { type: string }
        d_ext_attr1: { type: string, description: "MM/DD/YYYY." }
        d_ext_attr2: { type: string, description: "MM/DD/YYYY." }
        lines:
          type: array
          items:
            $ref: "#/components/schemas/InvoiceLine"
    InvoiceLine:
      type: object
      required:
        - pay_id
        - invoice_id
        - year
        - mon
        - category
        - type
        - effective_date
        - applies_from_date
        - applies_to_date
      properties:
        pay_id: { type: number, description: "Tango unique line-item identifier." }
        invoice_id: { type: number, description: "Parent invoice ID." }
        year: { type: integer, description: "Fiscal year." }
        mon: { type: integer, description: "Fiscal period." }
        comments: { type: string }
        description: { type: string }
        sys_gen_flag: { type: string, description: "One-time flag." }
        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." }
        net: { type: number }
        tax1: { type: number }
        tax2: { type: number }
        tax3: { type: number }
        tax4: { type: number }
        tax5: { type: number }
        total_tax: { type: number }
        gross: { type: number }
        tax_rate: { type: string }
        pay_currency: { type: string }
        consumption: { type: string }
        consum_uom: { type: string }
        account_string: { type: string }
        remit_message: { type: string }
        gl_acc: { 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 }
        payext2: { type: string }
        payext3: { type: string }
        payext4: { type: string }
        payext5: { type: string }
        payext6: { type: string }
        payext7: { type: string }
        payext8: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
