Non-aggregatable metrics

Versions 3.0+ of the Push API support sending metric values to specific periods of time, using from – to timestamps. 

If you want to create non-aggregatable (or unique) metrics, like for Churn Rate, Unique Visitor, etc., you need to store exact metric values for specific periods of time. Since such metrics cannot be aggregated, we simply can’t sum or take an average of daily values to display the monthly value. If you want to see the value for a Date Range, unique values need to be stored for each Date Range.

You can define these periods with the ‘periodFrom‘ and ‘periodTo‘ Date/Time.

  • cURL
  • PHP
  • JavaScript
  • Java
  • Go
  • Python
  • C#
curl https://push.databox.com/data \
-u <your_token>: \
-X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/vnd.databox.v2+json' \
-d '[
       {
         "key": "conversion_rate",
         "value" : 0.09,
         "periodFrom" : "2024-09-01 00:00:00",
         "periodTo" : "2024-09-05 00:00:00"
       }
 ]'

<?php

require_once __DIR__ . '/../../../vendor/autoload.php';

use Databox\Api\DefaultApi;
use Databox\ApiException;
use Databox\Configuration;
use Databox\Model\PushData as DataboxPushData;
use GuzzleHttp\Client;

execute();

function execute()
{
    // Configure HTTP basic authorization: basicAuth
    $config = Configuration::getDefaultConfiguration()
        ->setHost('https://push.databox.com')
        ->setUsername('<your_token>');

    $headers = [
        'Content-Type' => 'application/json',
        'Accept'       => 'application/vnd.databox.v2+json'
    ];

    $apiInstance = new DefaultApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
        new Client(['headers' => $headers]),
        $config
    );

    $pushData = (new DataboxPushData())
        ->setKey('conversion_rate') // for e.g. sessions
        ->setValue(0.9)
        ->setPeriodFrom('2024-09-01T00:00:00Z')
        ->setPeriodTo('2024-09-05T00:00:00Z')


    try {
        $apiInstance->dataPost([$pushData]);
        echo "Successfully pushed data to Databox";
    } catch (ApiException $e) {
        echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
    }
}

import {
  ApiResponse,
  Configuration,
  DataPostRequest,
  DefaultApi,
} from "databox";

const config: Configuration = new Configuration({
  basePath: "https://push.databox.com",
  username: "<your_token>",
  headers: {
    Accept: "application/vnd.databox.v2+json",
  },
});

const dataPostRequest: DataPostRequest = {
  pushData: [
    {
      key: "conversion_rate",
      value: 0.9,
      periodFrom: "2024-09-01 00:00:00",
      periodTo: "2024-09-05 00:00:00",
    },
  ],
};

const api = new DefaultApi(config);

try {
  api
    .dataPostRaw(dataPostRequest)
    .then((response: ApiResponse<void>) => response.raw.json())
    .then((responseBody) => {
      console.log("Response data", responseBody);
    });
} catch (error) {
  console.log("Error: ", error);
}

import org.databox.ApiClient;
import org.databox.ApiException;
import org.databox.Configuration;
import org.databox.api.DefaultApi;
import org.databox.auth.HttpBasicAuth;
import org.openapitools.client.model.PushData;
import org.openapitools.client.model.PushDataAttribute;

public class Example {
  public static void main(String[] args) {
    ApiClient defaultClient = Configuration.getDefaultApiClient();
    defaultClient.setBasePath("https://push.databox.com");
    defaultClient.addDefaultHeader("Accept", "application/vnd.databox.v2+json");

    HttpBasicAuth basicAuth = (HttpBasicAuth) defaultClient.getAuthentication("basicAuth");
    basicAuth.setUsername("Your_Databox_API_Token");

    PushData data = new PushData()
            .key("conversion_rate")
            .value(0.9f)
            .periodFrom("2024-09-01T00:00:00Z")
            .periodFrom("2024-09-05T00:00:00Z")

    DefaultApi apiInstance = new DefaultApi(defaultClient);
    try {
      apiInstance.dataPost(List.of(data));
    } catch (ApiException e) {
      e.printStackTrace();
    }
  }
}


package main

import (
  "context"
  "fmt"
  "os"
  "time"

  databox "github.com/databox/databox-go/databox"
)

const t = "" // Your Databox token

func main() {

  // Create a context with basic auth
  auth := context.WithValue(context.Background(), databox.ContextBasicAuth, databox.BasicAuth{UserName: t})

  // Create a configuration
  cfg := databox.NewConfiguration()
  cfg.DefaultHeader["Content-Type"] = "application/json"
  cfg.DefaultHeader["Accept"] = "application/vnd.databox.v2+json"

  // Create an API client
  api := databox.NewAPIClient(cfg)


  data := databox.NewPushData()
  data.SetKey("conversion_rate")
  data.SetValue(0.09)
  data.SetPeriodFrom("2024-09-01 00:00:00")
  data.SetPeriodTo("2024-09-05 00:00:00")

  // Push the data (send both PushData objects)
  r, err := api.DefaultAPI.DataPost(auth).PushData([]databox.PushData{*data1, *data2}).Execute()
  if err != nil {
    fmt.Fprintf(os.Stderr, "Error when calling `DefaultAPI.DataPost``: %v\n", err)
  }

  fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}


# Configuration setup for the Databox API client
# The API token is used as the username for authentication
# It's recommended to store your API token securely, e.g., in an environment variable
configuration = databox.Configuration(
    host="https://push.databox.com",
    username="<your_token>",
    password=""
)


# It's crucial to specify the correct Accept header for the API request
with databox.ApiClient(configuration, "Accept", "application/vnd.databox.v2+json", ) as api_client:
    api_instance = databox.DefaultApi(api_client)

    # Define the data to be pushed to the Databox Push API# Prepare the data you want to push to Databox
    push_data = [
        {
            "key": "conversion_rate",
            "value": 0.09,
            "periodFrom": "2024-09-01T00:00:00Z",
            "periodTo": "2024-09-05T00:00:00Z"
        }
    ]

    try:
        api_instance.data_post(push_data=push_data)
    except ApiException as e:
        # Handle exceptions that occur during the API call, such as invalid data or authentication issues
        pprint("API Exception occurred: %s\n" % e)
    except Exception as e:
        # Handle any other unexpected exceptions
        pprint("An unexpected error occurred: %s\n" % e)


using System.Diagnostics;
using Databox.Api;
using Databox.Client;
using Databox.Model;

namespace Example
{
  public class Example
  {
    public static async Task Main(string[] args)
    {

      Configuration config = new Configuration();
      config.BasePath = "https://push.databox.com";
      config.Username = "<your_token>";
      config.DefaultHeaders.Add("Accept", "application/vnd.databox.v2+json");


      HttpClient httpClient = new HttpClient();
      HttpClientHandler httpClientHandler = new HttpClientHandler();
      var apiInstance = new DefaultApi(httpClient, config, httpClientHandler);
      var dataPostRequest = new List<PushData>() {
        new PushData()
        {
            Key = "conversion_rate",
            Value = 0.9f,
            PeriodFrom = "2024-09-01T00:00:00Z",
            PeriodTo = "2024-09-05T00:00:00Z"
        }
      };

      try
      {
        var response = await apiInstance.DataPostWithHttpInfoAsync(dataPostRequest);
        Console.WriteLine(response.Data.ToString());
      }
      catch (ApiException e)
      {
        Console.WriteLine("Exception when calling DefaultApi.DataPostWithHttpInfo: " + e.Message);
        Console.WriteLine("Status Code: " + e.ErrorCode);
        Console.WriteLine(e.StackTrace);
      }
    }
  }
}