1+ <?php
2+
3+ require_once __DIR__ . '/../../../vendor/autoload.php ' ;
4+
5+ use Databox \Api \DefaultApi ;
6+ use Databox \ApiException ;
7+ use Databox \Configuration ;
8+ use Databox \Model \PushData as DataboxPushData ;
9+ use GuzzleHttp \Client ;
10+
11+ execute ();
12+
13+ function execute ()
14+ {
15+ // Configure HTTP basic authorization: basicAuth
16+ $ config = Configuration::getDefaultConfiguration ()
17+ ->setHost ('https://push.databox.com ' )
18+ ->setUsername ('<CUSTOM_DATA_TOKEN> ' )
19+ ->setUserAgent ('databox-designer-pushdata/2.0 ' );
20+
21+ $ headers = [
22+ 'Content-Type ' => 'application/json ' ,
23+ 'Accept ' => 'application/vnd.databox.v2+json '
24+ ];
25+
26+ $ apiInstance = new DefaultApi (
27+ // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
28+ // This is optional, `GuzzleHttp\Client` will be used as default.
29+ new Client (['headers ' => $ headers ]),
30+ $ config
31+ );
32+
33+ $ pushData = (new DataboxPushData ())
34+ ->setKey ('<METRIC_KEY_NAME> ' ) // for e.g. sessions
35+ ->setValue (125 )
36+ ->setDate ('2017-01-01T00:00:00Z ' ) // Date in ISO8601 format
37+ ->setUnit ('<UNIT> ' ) // for e.g. $
38+ ->setAttributes (['<DIMENSION_VALUE> ' ]); // for e.g. ['US']
39+
40+ try {
41+ $ apiInstance ->dataPost ([$ pushData ]);
42+ echo "Successfully pushed data to Databox " ;
43+ } catch (ApiException $ e ) {
44+ echo 'Exception when calling DefaultApi->dataPost: ' . $ e ->getMessage () . PHP_EOL . $ e ->getResponseBody () . PHP_EOL ;
45+ }
46+ }
0 commit comments