SDS P4 API

<back to all web services

Usage

Get usages from tablestorage

The following routes are available for this service:
GET/api/v5/meteringpoints/{Ean}/usages/{Aggregation}/{DateFrom}Get usages of a single asset with the selected aggregation starting from DateFrom from tablestorage
GET/api/v5/meteringpoints/{Ean}/usages/{Aggregation}/{DateFrom}/{DateTo}Get usages of a single asset with the selected aggregation and period from tablestorage
<?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';
}

enum PayloadFormat : string
{
    case UsageReturnCombined = 'UsageReturnCombined';
    case UsageReturn = 'UsageReturn';
    case UsageReturnAndTariff = 'UsageReturnAndTariff';
}

enum MeasurementSource : string
{
    case Detail = 'Detail';
    case Day = 'Day';
    case Month = 'Month';
    case Unknown = 'Unknown';
}

/** @description Get usages from tablestorage */
// @Api(Description="Get usages from tablestorage")
class Usage 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", Name="Ean")
        /** @var string|null */
        public ?string $Ean=null,

        /** @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 */
        // @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", 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. ", Name="DateTo")
        /** @var DateTime|null */
        public ?DateTime $DateTo=null,

        /** @description The output can be generated in a few formats. UsageReturnCombined: return values will be subtracted from the usage, UsageReturn: separate columns form usage and return (if available) and UsageReturnAndTariff: for both usage and return a column for tariff1 and tariff2. Default value: UsageReturnCombined */
        // @ApiMember(DataType="Enum", Description="The output can be generated in a few formats. UsageReturnCombined: return values will be subtracted from the usage, UsageReturn: separate columns form usage and return (if available) and UsageReturnAndTariff: for both usage and return a column for tariff1 and tariff2. Default value: UsageReturnCombined", Name="PayloadFormat")
        /** @var PayloadFormat|null */
        public ?PayloadFormat $PayloadFormat=null,

        /** @description See filter. Usages are available from the Detail or Day channel. Default value: Detail */
        // @ApiMember(DataType="Enum", Description="See filter. Usages are available from the Detail or Day channel. Default value: Detail", Name="Source")
        /** @var MeasurementSource|null */
        public ?MeasurementSource $Source=null,

        /** @description Add column with Dutch day (Default: false) */
        // @ApiMember(DataType="Boolean", Description="Add column with Dutch day (Default: false)", Name="AddDateNL")
        /** @var bool|null */
        public ?bool $AddDateNL=null,

        /** @description Add columns with CreatedOn and LastUpdated (Default: false) */
        // @ApiMember(DataType="Boolean", Description="Add columns with CreatedOn and LastUpdated (Default: false)", Name="AddTimestamps")
        /** @var bool|null */
        public ?bool $AddTimestamps=null,

        /** @description Add column with ean (Default: false) */
        // @ApiMember(DataType="Boolean", Description="Add column with ean (Default: false)", Name="AddEan")
        /** @var bool|null */
        public ?bool $AddEan=null,

        /** @description Create a row for each register instead of a column/field for each register (Default: false) */
        // @ApiMember(DataType="Boolean", Description="Create a row for each register instead of a column/field for each register (Default: false)", Name="RegistersInRows")
        /** @var bool|null */
        public ?bool $RegistersInRows=null,

        /** @description Gridoperator doesn't provided tariff information for the detail channel, but this can be calculated (Default: false) */
        // @ApiMember(DataType="Boolean", Description="Gridoperator doesn't provided tariff information for the detail channel, but this can be calculated (Default: false)", Name="CalculateDetailTariff")
        /** @var bool|null */
        public ?bool $CalculateDetailTariff=null,

        /** @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['PayloadFormat'])) $this->PayloadFormat = JsonConverters::from('PayloadFormat', $o['PayloadFormat']);
        if (isset($o['Source'])) $this->Source = JsonConverters::from('MeasurementSource', $o['Source']);
        if (isset($o['AddDateNL'])) $this->AddDateNL = $o['AddDateNL'];
        if (isset($o['AddTimestamps'])) $this->AddTimestamps = $o['AddTimestamps'];
        if (isset($o['AddEan'])) $this->AddEan = $o['AddEan'];
        if (isset($o['RegistersInRows'])) $this->RegistersInRows = $o['RegistersInRows'];
        if (isset($o['CalculateDetailTariff'])) $this->CalculateDetailTariff = $o['CalculateDetailTariff'];
        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->PayloadFormat)) $o['PayloadFormat'] = JsonConverters::to('PayloadFormat', $this->PayloadFormat);
        if (isset($this->Source)) $o['Source'] = JsonConverters::to('MeasurementSource', $this->Source);
        if (isset($this->AddDateNL)) $o['AddDateNL'] = $this->AddDateNL;
        if (isset($this->AddTimestamps)) $o['AddTimestamps'] = $this->AddTimestamps;
        if (isset($this->AddEan)) $o['AddEan'] = $this->AddEan;
        if (isset($this->RegistersInRows)) $o['RegistersInRows'] = $this->RegistersInRows;
        if (isset($this->CalculateDetailTariff)) $o['CalculateDetailTariff'] = $this->CalculateDetailTariff;
        if (isset($this->CalculateMissingUsages)) $o['CalculateMissingUsages'] = $this->CalculateMissingUsages;
        return empty($o) ? new class(){} : $o;
    }
}

PHP Usage DTOs

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

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

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

GET /api/v5/meteringpoints/{Ean}/usages/{Aggregation}/{DateFrom} HTTP/1.1 
Host: p4v8.smartdatasolutions.nl 
Accept: application/json