Analytics

Endpoint

📘

POST:https://api.ternary.app/analytics/query/load

Example 1

Querying for total credits over the previous invoice month based on specific measures:

  • absoluteCreditsCommittedUsageDiscount
  • absoluteCreditsCommittedUsageDiscountDollarBase
  • absoluteCreditsDiscount
  • absoluteCreditsFreeTier
  • absoluteCreditsPromotion
  • absoluteCreditsSubscriptionBenefit
  • absoluteCreditsSustainedUsageDiscount

Request

{
  "data_source": "Billing",
  "end_time": "2024-09-02T00:00:00.000Z",
  "measures": [
    "absoluteCreditsCommittedUsageDiscount",
    "absoluteCreditsCommittedUsageDiscountDollarBase",
    "absoluteCreditsDiscount",
    "absoluteCreditsFreeTier",
    "absoluteCreditsPromotion",
    "absoluteCreditsSubscriptionBenefit",
    "absoluteCreditsSustainedUsageDiscount"
  ],
  "offset": 0,
  "pre_agg_filters": [
    {
      "schema_field_name": "invoiceMonth",
      "operator": "gte",
      "values": [
        "202407"
      ]
    },
    {
      "schema_field_name": "invoiceMonth",
      "operator": "lte",
      "values": [
        "202407"
      ]
    }
  ],
  "start_time": "2024-06-28T00:00:00.000Z"
}

Response

{
    "response": [
        {
            "absoluteCreditsCommittedUsageDiscount": 0,
            "absoluteCreditsCommittedUsageDiscountDollarBase": 7.441224000000008,
            "absoluteCreditsDiscount": 90.81987999999998,
            "absoluteCreditsFreeTier": 0,
            "absoluteCreditsPromotion": 0,
            "absoluteCreditsSubscriptionBenefit": 0,
            "absoluteCreditsSustainedUsageDiscount": 25.37902499999999
        }
    ]
}


Example 2

Querying for project cost over the previous invoice month based on specific measures:

  • cost
  • credits

Request

{
  "data_source": "Billing",
  "dimensions": [
    "projectId"
  ],
  "end_time": "2024-09-02T00:00:00.000Z",
  "measures": [
    "cost",
    "credits"
  ],
  "offset": 0,
  "pre_agg_filters": [
    {
      "schema_field_name": "invoiceMonth",
      "operator": "gte",
      "values": [
        "202407"
      ]
    },
    {
      "schema_field_name": "invoiceMonth",
      "operator": "lte",
      "values": [
        "202407"
      ]
    }
  ],
  "start_time": "2024-06-28T00:00:00.000Z"
}

Response

{
    "response": [
        {
            "cost": 4.288550000000001,
            "credits": 0,
            "projectId": "ternary-demo-gcp-storage"
        },
        {
            "cost": 522.4753300000012,
            "credits": -123.6401290000001,
            "projectId": "ternary-demo-gcp"
        },
        {
            "cost": 968.0143717660004,
            "credits": 0,
            "projectId": "041804736319"
        },
        {
            "cost": 41.37624900000004,
            "credits": 0,
            "projectId": null
        },
        {
            "cost": 61.541630312699915,
            "credits": 0,
            "projectId": "337188550619"
        },
        {
            "cost": 21.57600011780001,
            "credits": 0,
            "projectId": "782056879377"
        },
        {
            "cost": 66,
            "credits": 0,
            "projectId": "pr-414533cc28e0bcdf"
        },
        {
            "cost": 99.75538920790015,
            "credits": 0,
            "projectId": "865437841033"
        }
    ]
}