SDS P4 API

<back to all web services

Graph

Get data for graph, usages and some statistical information

The following routes are available for this service:
GET/api/v6/meteringpoints/{Ean}/graph/{Aggregation}/{DateFrom}/{DateTo}Get usages based on aggregation starting from DateFrom to endDate
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


enum DateTimeFormat : string
{
    case ISO8601 = 'ISO8601';
    case UTC = 'UTC';
    case NL = 'NL';
    case NLOffset = 'NLOffset';
    case IN = 'IN';
    case INOffset = 'INOffset';
    case Unix = 'Unix';
    case UnixMillis = 'UnixMillis';
}

class Generic implements JsonSerializable
{
    public function __construct(
        /** @description Api-key. Used to provide credentials to the api. Can also be provided through the request headers with key: X-API-KEY */
        // @ApiMember(DataType="String", Description="Api-key. Used to provide credentials to the api. Can also be provided through the request headers with key: X-API-KEY", IsRequired=true, Name="ApiKey")
        /** @var string */
        public string $ApiKey='',

        /** @description Normally the result of the request is put inside a resultobject with some status information about the request. If you want the output as csv this outer object can be irritating. Default value: FALSE  */
        // @ApiMember(DataType="Boolean", Description="Normally the result of the request is put inside a resultobject with some status information about the request. If you want the output as csv this outer object can be irritating. Default value: FALSE ", Name="OnlyPayload")
        /** @var bool|null */
        public ?bool $OnlyPayload=null,

        /** @description Show the request as interpreted by the api. Useful to see how filters / dates are parsed. If no value us provided, the default value is: FALSE  */
        // @ApiMember(DataType="Boolean", Description="Show the request as interpreted by the api. Useful to see how filters / dates are parsed. If no value us provided, the default value is: FALSE ", Name="ShowRequest")
        /** @var bool|null */
        public ?bool $ShowRequest=null,

        /** @description Format all DateTime in the response object. If used in browser, sometimes ISO8601 is not correctly transformed. Enum options: ISO8601 (DEFAULT), UTC, NL, NLOffset, Unix, UnixMillis */
        // @ApiMember(DataType="Enum", Description="Format all DateTime in the response object. If used in browser, sometimes ISO8601 is not correctly transformed. Enum options: ISO8601 (DEFAULT), UTC, NL, NLOffset, Unix, UnixMillis", Name="DateTimeFormat")
        /** @var DateTimeFormat|null */
        public ?DateTimeFormat $DateTimeFormat=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['ApiKey'])) $this->ApiKey = $o['ApiKey'];
        if (isset($o['OnlyPayload'])) $this->OnlyPayload = $o['OnlyPayload'];
        if (isset($o['ShowRequest'])) $this->ShowRequest = $o['ShowRequest'];
        if (isset($o['DateTimeFormat'])) $this->DateTimeFormat = JsonConverters::from('DateTimeFormat', $o['DateTimeFormat']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->ApiKey)) $o['ApiKey'] = $this->ApiKey;
        if (isset($this->OnlyPayload)) $o['OnlyPayload'] = $this->OnlyPayload;
        if (isset($this->ShowRequest)) $o['ShowRequest'] = $this->ShowRequest;
        if (isset($this->DateTimeFormat)) $o['DateTimeFormat'] = JsonConverters::to('DateTimeFormat', $this->DateTimeFormat);
        return empty($o) ? new class(){} : $o;
    }
}

enum AggregationForAPI : string
{
    case None = 'None';
    case Hour = 'Hour';
    case Day = 'Day';
    case Week = 'Week';
    case Month = 'Month';
    case Year = 'Year';
}

/** @description Get data for graph, usages and some statistical information */
// @Api(Description="Get data for graph, usages and some statistical information")
class Graph extends Generic implements JsonSerializable
{
    /**
     * @param string $ApiKey
     * @param bool|null $OnlyPayload
     * @param bool|null $ShowRequest
     * @param DateTimeFormat|null $DateTimeFormat
     */
    public function __construct(
        string $ApiKey='',
        ?bool $OnlyPayload=null,
        ?bool $ShowRequest=null,
        ?DateTimeFormat $DateTimeFormat=null,
        /** @description Request of details of specific meteringpoint with Ean */
        // @ApiMember(DataType="EAN (18 numbers)", Description="Request of details of specific meteringpoint with Ean", IsRequired=true, Name="Ean")
        /** @var string */
        public string $Ean='',

        /** @description Aggregation level. The None-'level' will give the most detailed level available for the requested asset. If a level is requested that is not available or can be calculate, no data is returned. Enum options: None, Hour, Day, Week, Month */
        // @ApiMember(DataType="Enum", Description="Aggregation level. The None-'level' will give the most detailed level available for the requested asset. If a level is requested that is not available or can be calculate, no data is returned. Enum options: None, Hour, Day, Week, Month", IsRequired=true, Name="Aggregation")
        /** @var AggregationForAPI|null */
        public ?AggregationForAPI $Aggregation=null,

        /** @description Start date the usages are requested for */
        // @ApiMember(DataType="Date: yyyy-mm-dd", Description="Start date the usages are requested for", IsRequired=true, Name="DateFrom")
        /** @var DateTime */
        public DateTime $DateFrom=new DateTime(),

        /** @description End date the usages are requested for (this is included in the response). If no date is provided the DateTo will seven days from the DateFrom.  */
        // @ApiMember(DataType="Date: yyyy-mm-dd", Description="End date the usages are requested for (this is included in the response). If no date is provided the DateTo will seven days from the DateFrom. ", IsRequired=true, Name="DateTo")
        /** @var DateTime */
        public DateTime $DateTo=new DateTime(),

        /** @description calculate the usage of that period and divide it over the missing hours or 15 minute periods, but this can be calculated (Default: false) */
        // @ApiMember(DataType="Boolean", Description="calculate the usage of that period and divide it over the missing hours or 15 minute periods, but this can be calculated (Default: false)", Name="CalculateMissingUsages")
        /** @var bool|null */
        public ?bool $CalculateMissingUsages=null
    ) {
        parent::__construct($ApiKey,$OnlyPayload,$ShowRequest,$DateTimeFormat);
    }

    /** @throws Exception */
    public function fromMap($o): void {
        parent::fromMap($o);
        if (isset($o['Ean'])) $this->Ean = $o['Ean'];
        if (isset($o['Aggregation'])) $this->Aggregation = JsonConverters::from('AggregationForAPI', $o['Aggregation']);
        if (isset($o['DateFrom'])) $this->DateFrom = JsonConverters::from('DateTime', $o['DateFrom']);
        if (isset($o['DateTo'])) $this->DateTo = JsonConverters::from('DateTime', $o['DateTo']);
        if (isset($o['CalculateMissingUsages'])) $this->CalculateMissingUsages = $o['CalculateMissingUsages'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = parent::jsonSerialize();
        if (isset($this->Ean)) $o['Ean'] = $this->Ean;
        if (isset($this->Aggregation)) $o['Aggregation'] = JsonConverters::to('AggregationForAPI', $this->Aggregation);
        if (isset($this->DateFrom)) $o['DateFrom'] = JsonConverters::to('DateTime', $this->DateFrom);
        if (isset($this->DateTo)) $o['DateTo'] = JsonConverters::to('DateTime', $this->DateTo);
        if (isset($this->CalculateMissingUsages)) $o['CalculateMissingUsages'] = $this->CalculateMissingUsages;
        return empty($o) ? new class(){} : $o;
    }
}

PHP Graph DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml

HTTP + XML

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

GET /api/v6/meteringpoints/{Ean}/graph/{Aggregation}/{DateFrom}/{DateTo} HTTP/1.1 
Host: p4v8.smartdatasolutions.nl 
Accept: application/xml