---
title: Calculate raw revenue from usage data
slug: reference/calculate-raw-revenue-from-usage-data
docTags: 
createdAt: 2025-03-18T18:28:03.938Z
---

{
  "id": "OxeG7u-wEpxjmITlCJ2VU",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "https://app.amberflo.io/payments/analysis/raw-revenue-calculator",
    "servers": [
      {
        "url": "https://app.amberflo.io/payments/analysis/raw-revenue-calculator"
      }
    ],
    "name": "Calculate raw revenue from usage data",
    "description": "<p>Performs raw revenue analysis using actual usage data and pricing models.\nUse this endpoint to calculate revenue based on real usage patterns without applying complex pricing rules.</p>\n<p>Use this endpoint to:</p>\n<ul>\n<li>Calculate revenue from raw usage data</li>\n<li>Analyze actual vs projected revenue performance</li>\n<li>Model revenue impact of usage fluctuations</li>\n<li>Generate baseline revenue calculations for comparison</li>\n</ul>",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "object",
          "description": "Raw analysis parameters including usage data, pricing models, and calculation settings",
          "customType": "payment.analysis.modeling.raw.RawPriceAnalysisModel.in",
          "schema": [
            {
              "name": "key",
              "kind": "optional",
              "type": "object",
              "description": "Unique identifier and account information for this analysis model",
              "modelRef": "#/components/schemas/payment.analysis.modeling.PriceAnalysisModelKey.in",
              "customType": "payment.analysis.modeling.PriceAnalysisModelKey.in",
              "schema": [
                {
                  "name": "accountId",
                  "kind": "optional",
                  "type": "string",
                  "description": "Account identifier used as namespace for price analysis model templates in S3 storage",
                  "example": ""
                },
                {
                  "name": "id",
                  "kind": "optional",
                  "type": "string",
                  "description": "Required unique identifier for the specific price analysis model within the account scope",
                  "example": ""
                }
              ]
            },
            {
              "name": "type",
              "kind": "optional",
              "type": "string",
              "description": "Analysis model type identifier indicating this uses raw customer usage data",
              "example": "",
              "default": "raw"
            },
            {
              "name": "name",
              "kind": "optional",
              "type": "string",
              "description": "Human-readable name for this analysis model configuration",
              "example": ""
            },
            {
              "name": "description",
              "kind": "optional",
              "type": "string",
              "description": "Detailed description explaining the purpose and scope of this analysis",
              "example": ""
            },
            {
              "name": "timeRange",
              "kind": "optional",
              "type": "object",
              "description": "Start and end time boundaries for the revenue analysis period",
              "modelRef": "#/components/schemas/payment.common.TimeRange.in",
              "customType": "payment.common.TimeRange.in",
              "schema": [
                {
                  "name": "startTimeInSeconds",
                  "kind": "optional",
                  "type": "integer<int64>",
                  "description": "Unix timestamp marking the beginning of the time range in seconds",
                  "example": 0
                },
                {
                  "name": "endTimeInSeconds",
                  "kind": "optional",
                  "type": "integer<int64>",
                  "description": "Unix timestamp marking the end of time range or null for open-ended ranges",
                  "example": 0
                }
              ]
            },
            {
              "name": "analysisProductPlans",
              "kind": "optional",
              "type": "array",
              "description": "List of product pricing plans to compare in the revenue analysis",
              "modelRef": "#/components/schemas/payment.analysis.modeling.AnalysisProductPlan.in",
              "customType": "payment.analysis.modeling.AnalysisProductPlan.in[]",
              "schema": [
                {
                  "name": "id",
                  "kind": "optional",
                  "type": "string",
                  "description": "Unique identifier for this analysis product plan used to distinguish between different pricing scenarios in revenue calculations.",
                  "example": ""
                },
                {
                  "name": "referencePlan",
                  "kind": "optional",
                  "type": "string",
                  "description": "Optional reference to existing product plan ID used as baseline, with other properties providing overrides and customizations.",
                  "example": ""
                },
                {
                  "name": "planBillingPeriod",
                  "kind": "optional",
                  "type": "object",
                  "description": "Billing cycle duration configuration overriding the reference plan period or defining period for ad-hoc pricing scenarios.",
                  "modelRef": "#/components/schemas/payment.pricing.BillingPeriod.in",
                  "customType": "payment.pricing.BillingPeriod.in",
                  "schema": [
                    {
                      "name": "interval",
                      "kind": "optional",
                      "type": "string",
                      "description": "Time interval unit for billing cycle such as day, month, or year",
                      "modelRef": "#/components/schemas/payment.pricing.BillingPeriodInterval.in",
                      "customType": "payment.pricing.BillingPeriodInterval.in",
                      "schema": []
                    },
                    {
                      "name": "intervalsCount",
                      "kind": "optional",
                      "type": "integer<int32>",
                      "description": "Number of intervals in billing cycle with minimum value of 1",
                      "example": 0
                    }
                  ]
                },
                {
                  "name": "itemToPriceIdsOverrides",
                  "kind": "optional",
                  "type": "map",
                  "description": "Product item pricing overrides mapping item IDs to ProductItemPrice references, with null values indicating item removal from plan.",
                  "example": "",
                  "customType": "map<string, string>",
                  "schema": []
                },
                {
                  "name": "meterNameToPriceOverrides",
                  "kind": "optional",
                  "type": "map",
                  "description": "Direct meter pricing configurations mapping meter names to custom pricing state machines bypassing existing ProductItemPrice references.",
                  "example": "",
                  "customType": "map<string, payment.pricing.price.PriceStateMachineNode.in>",
                  "schema": []
                }
              ]
            },
            {
              "name": "timeGroupingInterval",
              "kind": "optional",
              "type": "string",
              "description": "Time interval for grouping revenue results such as daily or monthly",
              "modelRef": "#/components/schemas/common.aggregation.AggregationInterval.in",
              "customType": "common.aggregation.AggregationInterval.in",
              "schema": []
            },
            {
              "name": "updateTimeInSeconds",
              "kind": "optional",
              "type": "integer<int64>",
              "description": "Unix timestamp when this analysis model configuration was last updated",
              "example": 0
            },
            {
              "name": "customerGroupsUsageStats",
              "kind": "optional",
              "type": "array",
              "description": "Explicit customer usage data provided directly for revenue calculations",
              "modelRef": "#/components/schemas/payment.analysis.modeling.raw.RawCustomerGroupUsageStats.in",
              "customType": "payment.analysis.modeling.raw.RawCustomerGroupUsageStats.in[]",
              "schema": [
                {
                  "name": "customerGroupId",
                  "kind": "optional",
                  "type": "string",
                  "description": "Required unique identifier for the customer group used in revenue analysis calculations",
                  "example": ""
                },
                {
                  "name": "customersInGroup",
                  "kind": "optional",
                  "type": "integer<int32>",
                  "description": "Required positive integer representing the total number of customers in this group",
                  "example": 0
                },
                {
                  "name": "meterToCustomerUsageStatsMap",
                  "kind": "optional",
                  "type": "map",
                  "description": "Required mapping of meter API names to average usage statistics per customer in the group",
                  "example": "",
                  "customType": "map<string, payment.analysis.modeling.raw.RawMeterUsageStats.in>",
                  "schema": []
                }
              ]
            }
          ],
          "modelRef": "#/components/schemas/payment.analysis.modeling.raw.RawPriceAnalysisModel.in",
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [
        {
          "id": "apiKey",
          "name": "X-API-KEY",
          "kind": "optional",
          "type": "apiKey",
          "in": "header"
        }
      ]
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Returns raw revenue analysis results with detailed usage-based calculations and projections",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "Complete revenue analysis results containing simulated revenue calculations for multiple pricing plans analyzed by price analysis model tool",
            "customType": "payment.analysis.modeling.revenue.AnalyzedPlansRevenues.out",
            "schema": [
              {
                "name": "analyzedPlanRevenueList",
                "kind": "optional",
                "type": "array",
                "description": "Ordered list of revenue analysis results where first plan is pivot plan and remaining plans show comparative revenue projections",
                "modelRef": "#/components/schemas/payment.analysis.modeling.revenue.AnalyzedPlanRevenue.out",
                "customType": "payment.analysis.modeling.revenue.AnalyzedPlanRevenue.out[]",
                "schema": [
                  {
                    "name": "analysisPlanId",
                    "kind": "optional",
                    "type": "string",
                    "description": "Unique identifier of the analyzed pricing plan from the analysis product plan",
                    "example": ""
                  },
                  {
                    "name": "revenue",
                    "kind": "optional",
                    "type": "number",
                    "description": "Total revenue generated by this pricing plan summed across all customer groups in the analysis period",
                    "example": ""
                  },
                  {
                    "name": "revenuePercentageDiffFromPivotPlan",
                    "kind": "optional",
                    "type": "number",
                    "description": "Percentage difference in total revenue compared to pivot plan, calculated using pivot revenue comparison method",
                    "example": ""
                  },
                  {
                    "name": "customerGroupRevenueMap",
                    "kind": "optional",
                    "type": "map",
                    "description": "Revenue breakdown by customer group ID mapping each group to detailed revenue analysis results",
                    "example": "",
                    "customType": "map<string, payment.analysis.modeling.revenue.CustomerGroupRevenue.out>",
                    "schema": []
                  },
                  {
                    "name": "revenueValues",
                    "kind": "optional",
                    "type": "array",
                    "description": "Time-partitioned revenue values showing aggregated revenue progression across all customer groups over analysis period",
                    "modelRef": "#/components/schemas/payment.analysis.modeling.revenue.RevenueValue.out",
                    "customType": "payment.analysis.modeling.revenue.RevenueValue.out[]",
                    "schema": [
                      {
                        "name": "startTimeInSeconds",
                        "kind": "optional",
                        "type": "integer<int64>",
                        "description": "Unix timestamp marking start of revenue measurement period for aggregated revenue calculation",
                        "example": 0
                      },
                      {
                        "name": "revenue",
                        "kind": "optional",
                        "type": "number",
                        "description": "Total aggregated revenue amount for this time period across all product items and customer groups",
                        "example": ""
                      },
                      {
                        "name": "pivotPlanRevenue",
                        "kind": "optional",
                        "type": "number",
                        "description": "Total revenue amount that would have been generated by pivot plan for same time period",
                        "example": ""
                      },
                      {
                        "name": "revenuePercentageDiffFromPivotPlan",
                        "kind": "optional",
                        "type": "number",
                        "description": "Percentage difference in total revenue compared to pivot plan calculated using standard percentage difference algorithm",
                        "example": ""
                      }
                    ]
                  }
                ]
              }
            ],
            "modelRef": "#/components/schemas/payment.analysis.modeling.revenue.AnalyzedPlansRevenues.out",
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "400",
        "description": "Invalid analysis parameters or malformed usage data provided",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "401",
        "description": "Authentication required or invalid API key provided",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "403",
        "description": "Insufficient permissions to perform raw revenue analysis",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "404",
        "description": "Referenced usage data or pricing models not found",
        "jsonExample": "",
        "isExpanded": true
      },
      {
        "statusCode": "500",
        "description": "Internal server error occurred during raw revenue calculation",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "mgRULY5f_996lN0dK_a3X",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url https://app.amberflo.io/payments/analysis/raw-revenue-calculator \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"type\": \"raw\"\n     }'"
        },
        {
          "id": "1V2EhrvGqNI0uHYniIKJk",
          "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   \"type\": \"raw\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"https://app.amberflo.io/payments/analysis/raw-revenue-calculator\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "UJt1WJdEpuVImtzLj126Y",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"https://app.amberflo.io/payments/analysis/raw-revenue-calculator\")\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   \"type\": \"raw\"\n})\n\nresponse = https.request(request)\nputs response.read_body\n"
        },
        {
          "id": "qodn9Isi6tqVFmWtST6ft",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"https://app.amberflo.io/payments/analysis/raw-revenue-calculator\"\n\npayload = json.dumps({\n   \"type\": \"raw\"\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": "mgRULY5f_996lN0dK_a3X"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-200",
          "language": "200",
          "code": "// Returns raw revenue analysis results with detailed usage-based calculations and projections\n{\n  \"analyzedPlanRevenueList\": [\n    {\n      \"analysisPlanId\": \"\",\n      \"revenue\": 0,\n      \"revenuePercentageDiffFromPivotPlan\": 0,\n      \"customerGroupRevenueMap\": \"\",\n      \"revenueValues\": [\n        {\n          \"startTimeInSeconds\": \"\",\n          \"revenue\": 0,\n          \"pivotPlanRevenue\": 0,\n          \"revenuePercentageDiffFromPivotPlan\": 0\n        }\n      ]\n    }\n  ]\n}"
        },
        {
          "id": "response-1-400",
          "language": "400",
          "code": "// Invalid analysis parameters or malformed usage data provided\n"
        },
        {
          "id": "response-2-401",
          "language": "401",
          "code": "// Authentication required or invalid API key provided\n"
        },
        {
          "id": "response-3-403",
          "language": "403",
          "code": "// Insufficient permissions to perform raw revenue analysis\n"
        },
        {
          "id": "response-4-404",
          "language": "404",
          "code": "// Referenced usage data or pricing models not found\n"
        },
        {
          "id": "response-5-500",
          "language": "500",
          "code": "// Internal server error occurred during raw revenue calculation\n"
        }
      ],
      "selectedLanguageId": "response-0-200"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}