PHP code example of markmorgan / octopus-energy

1. Go to this page and download the library: Download markmorgan/octopus-energy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

markmorgan / octopus-energy example snippets


$apiKey = 'my-octopus-apikey';

$client = new \OctopusEnergy\Client($apiKey);

$productsSearch = $client->products->all();

$productCode = 'VAR-21-09-29';
$product = $client->products->get($productCode);

$mpan = 'YOUR MPAN NUMBER';
$meter = $client->meters->getElectricityMeter($mpan);

$mpan = 'YOUR MPAN NUMBER';
$serialNumber = 'YOUR METER SERIAL NUMBER';

$consumptionSearch = $client->meters->getElectricityMeterConsumption(
    $mpan,
    $serialNumber
);

$fromDate = new \DateTime();
$fromDate->setTimestamp(1640995201);    // Jan 1st 2022

$toDate = new \DateTime();
$toDate->setTimestamp(1643673601);      // Feb 1st 2022

$pageNumber = 1;
$consumptionSearch = $client->meters->getElectricityMeterConsumption(
    $mpan,
    $serialNumber,
    $pageNumber,
    $fromDate,
    $toDate
);

// fetch all grid supply point info
$gspSearch = $client->industry->getGridSupplyPoints();

// fetch grid supply point info for a postcode
$postcode = 'cf104uw';
$gspSearch = $client->industry->getGridSupplyPoints($postcode);