openapi: 3.1.0
info:
  title: Tango Project Invoice Outbound API
  version: "1.1"
  description: |
    Async REST API for retrieving approved invoice records from Tango. Client
    initiates a GET against the invoices endpoint; Tango returns a `gu_id`
    immediately. Client then calls the Status endpoint with that `gu_id` to
    retrieve the full invoice payload (the same gu_id can be re-used multiple
    times to fetch the same batch). On successful export, Tango flags the
    invoices as `Exported`.

    Each invoice has a header plus an array of detail line items. Any field
    that is unconfigured or null in Tango is omitted from the JSON.
  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: Invoices
  - name: Status
paths:
  /v1/projectmgmt/batch/invoices:
    get:
      summary: Initiate invoice export (async)
      operationId: getInvoicesBatch
      tags: [Invoices]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      responses:
        "200":
          description: |
            Async ack returning a gu_id. On error the gu_id is not generated.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
              examples:
                ok:
                  value:
                    status: "OK"
                    status_message: ""
                    gu_id: "721c54c4-c7aa-4fa1-8fdfd6-c0cee161694d"
  /v1/batch/status:
    get:
      summary: Retrieve exported invoice records by gu_id
      description: |
        Returns the invoice records associated with the gu_id. Same gu_id can be
        polled repeatedly. Any field that's null in Tango is omitted from the
        JSON response entirely.
      operationId: getInvoicesByGuId
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema:
            type: string
            format: uuid
      responses:
        "200":
          description: Invoice records.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InvoiceBatchResponse"
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
          description: Omitted on error.
    InvoiceBatchResponse:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/InvoiceRecord"
    InvoiceRecord:
      type: object
      description: |
        Invoice header. Required fields are not annotated in the source data-mapping
        table for outbound; all are emitted only when populated in Tango.
      properties:
        inv_id:
          type: number
          description: Tango-generated unique invoice ID.
        inv_number:
          type: string
          description: Client-defined invoice number.
        inv_type:
          type: string
          description: Tango standard codes — `REGULAR` / `RETAINAGE`.
        inv_date:
          type: string
          description: "MM/DD/YYYY."
        po_number:
          type: string
        project_number:
          type: string
        location_number:
          type: string
        supplier_number:
          type: string
        supplier_site_number:
          type: string
        currency:
          type: string
          description: ISO 4217 3-letter code (doc says "ISO 3 Char currency code").
        pct_inv_amt:
          type: number
        exchange_rate:
          type: number
        payment_terms:
          type: string
        retainage_pct:
          type: number
        status:
          type: string
        submitted_by:
          type: string
        approved_by:
          type: string
        created_by:
          type: string
        creation_date:
          type: string
          description: "MM/DD/YYYY."
        state:
          type: string
        zip:
          type: string
        final_invoice:
          type: string
          description: "Y/N flag."
        details:
          type: array
          items:
            $ref: "#/components/schemas/InvoiceDetail"
    InvoiceDetail:
      type: object
      properties:
        detail_id:
          type: number
          description: Tango-generated unique invoice detail ID.
        task_id:
          type: number
        seq_no:
          type: number
        currency:
          type: string
        po_amount:
          type: number
        amount:
          type: number
        remaining_bal:
          type: number
        net_amount:
          type: number
          description: Invoice amount rounded to 2 decimals.
        retainage_pct:
          type: number
        tax_group:
          type: string
        tax_rate:
          type: number
        vendor_tax:
          type: number
          description: Tax amount rounded to 2 decimals.
        accrued_tax:
          type: number
        seg1: { type: string }
        seg2: { type: string }
        seg3: { type: string }
        seg4: { type: string }
        seg5: { type: string }
        seg6: { type: string }
        acct_code:
          type: string
        comments:
          type: string
        nattr1:
          type: string
        nattr2:
          type: string
        task_name:
          type: string
        line_item_name:
          type: string
        division:
          type: string
security:
  - xClientHeader: []
    xApiKeyHeader: []
