openapi: 3.1.0
info:
  title: Tango GL Outbound API
  version: "1.4"
  description: |
    Async REST API: client GETs approved journal entries (batch accruals) from
    Tango for booking to its general ledger. Two-call pattern with gu_id and
    pagination. Page size 5000.

    Source design uses 3-step internal flow:
      1. Generate accruals from all sources → Batch Journal Entries screen
      2. Approve the JEs
      3. Transmit via this API on client request

    Only `lease status = Active` and `batch status = APPROVED` rows are
    returned. After processing, the posting status on the accounting schedule
    is set to PROCESSED.
  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: GL Accruals
  - name: Status
paths:
  /v1/leasemgmt/accurals:
    get:
      summary: Initiate GL accrual export (async)
      description: |
        Endpoint path is `/accurals` in the source design doc (typo for
        "accruals"). Preserved verbatim — confirm with the API team.
      operationId: getGLAccrualsBatch
      tags: [GL Accruals]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: fiscal_year
          required: false
          schema: { type: integer }
        - in: query
          name: fiscal_period
          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 journal entries by gu_id
      operationId: getGLAccrualsByGuId
      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 GL records.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccrualPage"
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 }
    AccrualPage:
      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/AccrualRecord"
    AccrualRecord:
      type: object
      required:
        - accrual_id
        - batch_id
        - location_num
        - lease_num
        - gl_type
        - fiscal_period
        - fiscal_year
      properties:
        accrual_id: { type: number, description: "Tango unique accrual identifier." }
        batch_id: { type: number, description: "Tango unique batch identifier." }
        location_num: { type: string }
        lease_num: { type: string }
        legal_entity: { type: string }
        gl_type:
          type: string
          description: "Accrual type — e.g., `842-BSE`."
        accrual_description: { type: string }
        line_desc: { type: string }
        posting_date:
          type: string
          description: "MM/DD/YYYY. Last day of the fiscal period."
        fiscal_period: { type: string }
        fiscal_year: { type: string }
        period_amount:
          type: string
          description: |
            Numeric amount per fiscal period. Source types as VARCHAR;
            consumers may need to parse.
        lease_finacials_group:
          type: string
          description: |
            "lease_finacials_group" — typo in source ("finacials" not "financials"),
            preserved verbatim.
        je_number: { type: string, description: "Journal entry number." }
        accounting_schedule_treatment:
          type: string
          description: "FASB 840/842, IFRS16."
        currency: { type: string }
        brand: { type: string }
        department: { type: string }
        region: { type: string }
        account_classification:
          type: string
          enum: [Operating, Finance]
        asset_type:
          type: string
          description: "RE / Non-RE."
        expense_type: { type: string, description: "Rent / Tenant Allowance / etc." }
        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 }
        comments: { type: string }
        country: { type: string }
        credit_account: { type: string }
        debit_Account:
          type: string
          description: |
            "debit_Account" — mixed case in source (capital `A`), preserved
            verbatim. Confirm with API team whether the wire format is
            `debit_account` or `debit_Account`.
        lease_name: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
