---
title: Query the cost data scoped to the customer
slug: reference/query-the-cost-data-scoped-to-the-customer
docTags: 
createdAt: 2024-09-30T17:03:00.667Z
---

{
  "id": "DkW1_mCI23PEvMxmkjdJH",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://app.amberflo.io/customer-portal/usage-cost",
    "servers": [
      {
        "url": "https://app.amberflo.io/customer-portal/usage-cost"
      }
    ],
    "name": "Query the cost data scoped to the customer",
    "description": "",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [
        {
          "kind": "required",
          "name": "sessionToken",
          "type": "string",
          "description": "<p>A required session token used to authenticate API calls made on behalf of a customer. This token is obtained from the <code>Create a session</code> endpoint and must be included with every request to authorize access.</p>"
        }
      ],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "object",
          "description": "",
          "customType": "usage-cost-request",
          "schema": [
            {
              "name": "filters",
              "kind": "optional",
              "type": "map",
              "description": "key can be: product_id, product_plan_id, product_item_key, product_item_name, meter_api_name, product_plan_name, or any dimension name",
              "example": "",
              "customType": "map<string, string>",
              "schema": []
            },
            {
              "name": "groupBy",
              "kind": "optional",
              "type": "array",
              "description": "key can be: customer_id, product_id, product_plan_id, product_item_key, product_item_name, meter_api_name, product_plan_name, or any dimension name",
              "example": "",
              "itemType": "string",
              "customType": "string[]",
              "itemExample": "",
              "itemDefault": ""
            },
            {
              "name": "productId",
              "kind": "optional",
              "type": "string",
              "description": "Product ID as defined in account pricing. Change from default only if you have multiple products.",
              "example": "",
              "default": "1"
            },
            {
              "name": "take",
              "kind": "optional",
              "type": "object",
              "example": "",
              "schema": [
                {
                  "name": "isAscending",
                  "kind": "optional",
                  "type": "boolean",
                  "example": ""
                },
                {
                  "name": "limit",
                  "kind": "optional",
                  "type": "integer",
                  "example": 0
                }
              ]
            },
            {
              "name": "page",
              "kind": "optional",
              "type": "object",
              "description": "if used in conjunction with take, the take limit applies before the pagination",
              "example": "",
              "schema": [
                {
                  "name": "number",
                  "kind": "optional",
                  "type": "integer",
                  "description": "page number to return",
                  "example": 0
                },
                {
                  "name": "size",
                  "kind": "optional",
                  "type": "integer",
                  "description": "max number of results per page",
                  "example": 0
                },
                {
                  "name": "token",
                  "kind": "optional",
                  "type": "string",
                  "description": "a token from a previous query result `pageInfo.pageToken`. including improves performance.",
                  "example": ""
                }
              ]
            },
            {
              "name": "timeGroupingInterval",
              "kind": "optional",
              "type": "string<HOUR | DAY | WEEK | MONTH>",
              "example": "",
              "default": "DAY"
            },
            {
              "name": "timeRange",
              "kind": "optional",
              "type": "object",
              "example": "",
              "schema": [
                {
                  "name": "endTimeInSeconds",
                  "kind": "optional",
                  "type": "integer",
                  "example": 0
                },
                {
                  "name": "startTimeInSeconds",
                  "kind": "optional",
                  "type": "integer",
                  "example": 0
                }
              ]
            }
          ],
          "modelRef": "#/components/schemas/usage-cost-request",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "api_key",
          "name": "x-api-key",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        }
      ]
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Successful response",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "customType": "usage-cost-response",
            "schema": [
              {
                "name": "costList",
                "kind": "optional",
                "type": "array",
                "example": "",
                "itemType": "object",
                "customType": "object[]",
                "schema": [
                  {
                    "name": "costs",
                    "kind": "optional",
                    "type": "array",
                    "example": "",
                    "itemType": "object",
                    "customType": "object[]",
                    "schema": [
                      {
                        "name": "meterUnitsPercentageDiff",
                        "kind": "optional",
                        "type": "number",
                        "example": ""
                      },
                      {
                        "name": "meteredUnits",
                        "kind": "optional",
                        "type": "number",
                        "example": ""
                      },
                      {
                        "name": "prepaidUsed",
                        "kind": "optional",
                        "type": "number",
                        "description": "Prepaid used to pay for the specific usage.",
                        "example": ""
                      },
                      {
                        "name": "price",
                        "kind": "optional",
                        "type": "number",
                        "description": "Describes the usage bill after discounts, but before prepaid was applied.",
                        "example": ""
                      },
                      {
                        "name": "priceBeforeDiscounts",
                        "kind": "optional",
                        "type": "number",
                        "example": ""
                      },
                      {
                        "name": "pricePercentageDiff",
                        "kind": "optional",
                        "type": "number",
                        "example": ""
                      },
                      {
                        "name": "startTimeInSeconds",
                        "kind": "optional",
                        "type": "integer",
                        "example": 0
                      }
                    ]
                  },
                  {
                    "name": "groupInfos",
                    "kind": "optional",
                    "type": "map",
                    "example": "",
                    "customType": "map<string, string>",
                    "schema": []
                  },
                  {
                    "name": "meteredUnits",
                    "kind": "optional",
                    "type": "number",
                    "example": ""
                  },
                  {
                    "name": "prepaidUsed",
                    "kind": "optional",
                    "type": "number",
                    "description": "Prepaid used to pay for the specific usage.",
                    "example": ""
                  },
                  {
                    "name": "price",
                    "kind": "optional",
                    "type": "number",
                    "description": "Describes the usage bill after discounts, but before prepaid was applied.",
                    "example": ""
                  },
                  {
                    "name": "priceBeforeDiscounts",
                    "kind": "optional",
                    "type": "number",
                    "example": ""
                  },
                  {
                    "name": "priceMinusPrepaid",
                    "kind": "optional",
                    "type": "number",
                    "description": "Describes the usage bill to pay after discounts - this is the portion of the bill not paid in advance using prepaid.",
                    "example": ""
                  }
                ]
              },
              {
                "name": "key",
                "kind": "optional",
                "type": "object",
                "example": "",
                "schema": [
                  {
                    "name": "filters",
                    "kind": "optional",
                    "type": "map",
                    "example": "",
                    "customType": "map<string, string>",
                    "schema": []
                  },
                  {
                    "name": "groupBy",
                    "kind": "optional",
                    "type": "array",
                    "example": "",
                    "itemType": "string",
                    "customType": "string[]",
                    "itemExample": "",
                    "itemDefault": ""
                  },
                  {
                    "name": "productId",
                    "kind": "optional",
                    "type": "string",
                    "example": ""
                  },
                  {
                    "name": "take",
                    "kind": "optional",
                    "type": "object",
                    "example": "",
                    "schema": [
                      {
                        "name": "isAscending",
                        "kind": "optional",
                        "type": "boolean",
                        "example": ""
                      },
                      {
                        "name": "limit",
                        "kind": "optional",
                        "type": "integer",
                        "example": 0
                      }
                    ]
                  },
                  {
                    "name": "timeGroupingInterval",
                    "kind": "optional",
                    "type": "string<HOUR | DAY | WEEK | MONTH>",
                    "example": ""
                  },
                  {
                    "name": "timeRange",
                    "kind": "optional",
                    "type": "object",
                    "example": "",
                    "schema": [
                      {
                        "name": "endTimeInSeconds",
                        "kind": "optional",
                        "type": "integer",
                        "description": "Utc Time in seconds.",
                        "example": 0
                      },
                      {
                        "name": "startTimeInSeconds",
                        "kind": "optional",
                        "type": "integer",
                        "description": "Utc Time in seconds.",
                        "example": 0
                      }
                    ]
                  }
                ]
              },
              {
                "name": "pageInfo",
                "kind": "optional",
                "type": "object",
                "example": "",
                "schema": [
                  {
                    "name": "pageNumber",
                    "kind": "optional",
                    "type": "integer",
                    "description": "requested page number",
                    "example": 0
                  },
                  {
                    "name": "pageSize",
                    "kind": "optional",
                    "type": "integer",
                    "description": "requested page size",
                    "example": 0
                  },
                  {
                    "name": "pageToken",
                    "kind": "optional",
                    "type": "string",
                    "description": "Token from the query. Providing in paginated queries improves response time.",
                    "example": ""
                  },
                  {
                    "name": "totalPages",
                    "kind": "optional",
                    "type": "integer",
                    "description": "total number of pages",
                    "example": 0
                  },
                  {
                    "name": "totalResults",
                    "kind": "optional",
                    "type": "integer",
                    "description": "total number of results",
                    "example": 0
                  }
                ]
              },
              {
                "name": "secondsSinceEpochIntervals",
                "kind": "optional",
                "type": "array",
                "example": "",
                "itemType": "integer",
                "customType": "integer[]",
                "itemExample": "",
                "itemDefault": ""
              }
            ],
            "modelRef": "#/components/schemas/usage-cost-response",
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "9aEw8zJTGZgsvUuTlnItz",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url 'https://app.amberflo.io/customer-portal/usage-cost?sessionToken=string' \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"productId\": \"1\",\n     \"timeGroupingInterval\": \"DAY\"\n     }'"
        },
        {
          "id": "F5YDGqBLwvm8t9F-KR46W",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"productId\": \"1\",\n   \"timeGroupingInterval\": \"DAY\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://app.amberflo.io/customer-portal/usage-cost?sessionToken=string\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "Gi4XOi1-a7Zp0isxu-rUo",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://app.amberflo.io/customer-portal/usage-cost?sessionToken=string\")\n\nhttps = Net::HTTP.new(url.host, url.port)\nhttps.use_ssl = true\n\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"productId\": \"1\",\n   \"timeGroupingInterval\": \"DAY\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "62i4NZ3O0jAAaNbpkgN62",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://app.amberflo.io/customer-portal/usage-cost?sessionToken=string\"\n\npayload = json.dumps({\n   \"productId\": \"1\",\n   \"timeGroupingInterval\": \"DAY\"\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "9aEw8zJTGZgsvUuTlnItz"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Successful response\n{\n  \"costList\": [\n    {\n      \"costs\": [\n        {\n          \"meterUnitsPercentageDiff\": 0,\n          \"meteredUnits\": 0,\n          \"prepaidUsed\": 0,\n          \"price\": 0,\n          \"priceBeforeDiscounts\": 0,\n          \"pricePercentageDiff\": 0,\n          \"startTimeInSeconds\": 0\n        }\n      ],\n      \"groupInfos\": \"\",\n      \"meteredUnits\": 0,\n      \"prepaidUsed\": 0,\n      \"price\": 0,\n      \"priceBeforeDiscounts\": 0,\n      \"priceMinusPrepaid\": 0\n    }\n  ],\n  \"key\": {\n    \"filters\": \"\",\n    \"groupBy\": [\n      \"\"\n    ],\n    \"productId\": \"\",\n    \"take\": {\n      \"isAscending\": false,\n      \"limit\": 0\n    },\n    \"timeGroupingInterval\": \"\",\n    \"timeRange\": {\n      \"endTimeInSeconds\": 0,\n      \"startTimeInSeconds\": 0\n    }\n  },\n  \"pageInfo\": {\n    \"pageNumber\": 0,\n    \"pageSize\": 0,\n    \"pageToken\": \"\",\n    \"totalPages\": 0,\n    \"totalResults\": 0\n  },\n  \"secondsSinceEpochIntervals\": [\n    0\n  ]\n}"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": "",
      "id": "YJ9AV5EZBvFFdVL44I0L8"
    }
  ]
}