Skip to main content
POST
/
costs
/
analytics-v2
Get combined revenue and cost analytics (V2)
curl --request POST \
  --url https://us.api.flexprice.io/v1/costs/analytics-v2 \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "end_time": "2023-11-07T05:31:56Z",
  "expand": [
    "<string>"
  ],
  "external_customer_id": "<string>",
  "feature_ids": [
    "<string>"
  ],
  "limit": 123,
  "offset": 123,
  "start_time": "2023-11-07T05:31:56Z"
}
'
import requests

url = "https://us.api.flexprice.io/v1/costs/analytics-v2"

payload = {
"end_time": "2023-11-07T05:31:56Z",
"expand": ["<string>"],
"external_customer_id": "<string>",
"feature_ids": ["<string>"],
"limit": 123,
"offset": 123,
"start_time": "2023-11-07T05:31:56Z"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
end_time: '2023-11-07T05:31:56Z',
expand: ['<string>'],
external_customer_id: '<string>',
feature_ids: ['<string>'],
limit: 123,
offset: 123,
start_time: '2023-11-07T05:31:56Z'
})
};

fetch('https://us.api.flexprice.io/v1/costs/analytics-v2', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://us.api.flexprice.io/v1/costs/analytics-v2",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'end_time' => '2023-11-07T05:31:56Z',
'expand' => [
'<string>'
],
'external_customer_id' => '<string>',
'feature_ids' => [
'<string>'
],
'limit' => 123,
'offset' => 123,
'start_time' => '2023-11-07T05:31:56Z'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://us.api.flexprice.io/v1/costs/analytics-v2"

payload := strings.NewReader("{\n \"end_time\": \"2023-11-07T05:31:56Z\",\n \"expand\": [\n \"<string>\"\n ],\n \"external_customer_id\": \"<string>\",\n \"feature_ids\": [\n \"<string>\"\n ],\n \"limit\": 123,\n \"offset\": 123,\n \"start_time\": \"2023-11-07T05:31:56Z\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://us.api.flexprice.io/v1/costs/analytics-v2")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"end_time\": \"2023-11-07T05:31:56Z\",\n \"expand\": [\n \"<string>\"\n ],\n \"external_customer_id\": \"<string>\",\n \"feature_ids\": [\n \"<string>\"\n ],\n \"limit\": 123,\n \"offset\": 123,\n \"start_time\": \"2023-11-07T05:31:56Z\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://us.api.flexprice.io/v1/costs/analytics-v2")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"end_time\": \"2023-11-07T05:31:56Z\",\n \"expand\": [\n \"<string>\"\n ],\n \"external_customer_id\": \"<string>\",\n \"feature_ids\": [\n \"<string>\"\n ],\n \"limit\": 123,\n \"offset\": 123,\n \"start_time\": \"2023-11-07T05:31:56Z\"\n}"

response = http.request(request)
puts response.read_body
{
  "cost_analytics": [
    {
      "cost_by_period": [
        {
          "cost": "<string>",
          "event_count": 123,
          "quantity": "<string>",
          "timestamp": "<string>"
        }
      ],
      "costsheet_id": "<string>",
      "currency": "<string>",
      "customer_id": "<string>",
      "external_customer_id": "<string>",
      "meter": {
        "aggregation": {
          "expression": "<string>",
          "field": "<string>",
          "group_by": "<string>",
          "multiplier": "<string>"
        },
        "created_at": "2023-11-07T05:31:56Z",
        "created_by": "<string>",
        "environment_id": "<string>",
        "event_name": "<string>",
        "filters": [
          {
            "key": "<string>",
            "values": [
              "<string>"
            ]
          }
        ],
        "id": "<string>",
        "name": "<string>",
        "tenant_id": "<string>",
        "updated_at": "2023-11-07T05:31:56Z",
        "updated_by": "<string>"
      },
      "meter_id": "<string>",
      "meter_name": "<string>",
      "price": {
        "amount": "<string>",
        "billing_cadence": "RECURRING",
        "billing_period_count": 123,
        "conversion_rate": "<string>",
        "created_at": "2023-11-07T05:31:56Z",
        "created_by": "<string>",
        "currency": "<string>",
        "description": "<string>",
        "display_amount": "<string>",
        "display_name": "<string>",
        "display_price_unit_amount": "<string>",
        "end_date": "2023-11-07T05:31:56Z",
        "entity_id": "<string>",
        "environment_id": "<string>",
        "group_id": "<string>",
        "id": "<string>",
        "lookup_key": "<string>",
        "metadata": {},
        "meter_id": "<string>",
        "min_quantity": "<string>",
        "parent_price_id": "<string>",
        "price_unit": "<string>",
        "price_unit_amount": "<string>",
        "price_unit_id": "<string>",
        "price_unit_tiers": [
          {
            "flat_amount": "<string>",
            "unit_amount": "<string>",
            "up_to": 123
          }
        ],
        "sequence": 123,
        "start_date": "2023-11-07T05:31:56Z",
        "tenant_id": "<string>",
        "tiers": [
          {
            "flat_amount": "<string>",
            "unit_amount": "<string>",
            "up_to": 123
          }
        ],
        "transform_quantity": {
          "divide_by": 123
        },
        "trial_period_days": 123,
        "updated_at": "2023-11-07T05:31:56Z",
        "updated_by": "<string>"
      },
      "price_id": "<string>",
      "properties": {},
      "source": "<string>",
      "total_cost": "<string>",
      "total_events": 123,
      "total_quantity": "<string>"
    }
  ],
  "currency": "<string>",
  "end_time": "2023-11-07T05:31:56Z",
  "margin": "<string>",
  "margin_percent": "<string>",
  "roi": "<string>",
  "roi_percent": "<string>",
  "start_time": "2023-11-07T05:31:56Z",
  "total_cost": "<string>",
  "total_revenue": "<string>"
}
{
"http_status_code": 123,
"message": "<string>"
}
{
"http_status_code": 123,
"message": "<string>"
}

Authorizations

x-api-key
string
header
required

Enter your API key in the format x-api-key <api-key>*

Body

application/json

Combined analytics request (start_time/end_time optional - defaults to last 7 days)

end_time
string<date-time>
expand
string[]

Expand options - specify which entities to expand

external_customer_id
string

Optional - for specific customer

feature_ids
string[]

Additional filters

limit
integer

Pagination

offset
integer
start_time
string<date-time>

Time range fields (optional - defaults to last 7 days if not provided)

Response

OK

cost_analytics
object[]

Cost analytics array (flattened from nested structure)

currency
string
end_time
string<date-time>
margin
string

Revenue - Cost

margin_percent
string

(Margin / Revenue) * 100

roi
string

(Revenue - Cost) / Cost

roi_percent
string

ROI * 100

start_time
string<date-time>
total_cost
string
total_revenue
string

Derived metrics