Skip to Content
Octopus Energy Packages

Fetch Measurement Data

Fetch property measurements without mixing supply points

Measurement queries need the shared timeframe created in Create the Shell, plus market supply point descriptors. A descriptor identifies one supply point on the property and attaches it to a normalized utility such as electricity or gas.

Some properties have more than one supply point for the same utility. The safest default is to fetch all selected supply points together, then keep each supply point separate until the UI intentionally aggregates them.

What you'll build

By the end of this guide, ConsumptionOverview will resolve market supply point descriptors and fetch normalized measurement records for the shared timeframe.

If your product only needs a single combined electricity total and a single combined gas total, grouping by utility can be enough. Treat that as an aggregation choice, not the default data shape.

Market supply points define identity

Treat market supply points as the source of truth for meter identity. Use groupMeasurements(records, {matching}) when rendering cards so card identity, ordering, and empty states come from the resolved descriptors.

Define the market mapping

The GraphQL API returns territory-specific market names. Map those names to the package utilities once in your app, then reuse the mapping wherever you fetch supply points.

import type { UtilityMarkets } from "@octopus-energy/measurements/market-supply-points";

const utilityMarkets: UtilityMarkets = {
  electricity: ["GBR_ELECTRICITY"],
  gas: ["GBR_GAS"],
};

These values are examples. Replace them with the market names used by your territory or product.

Fetch supply points

Start from the descriptors returned by the Market Supply Points API. They carry the market supply point ID and normalized utility that we use for fetching and grouping.

_components/consumption-overview.tsx
import { useQuery } from "@tanstack/react-query";
import { marketSupplyPointsQueryOptions } from "@octopus-energy/measurements/react-query";

const marketSupplyPointsQuery = useQuery(
  marketSupplyPointsQueryOptions(client, {
    accountNumber,
    propertyId,
    utilityMarkets,
  }),
);

const marketSupplyPoints = marketSupplyPointsQuery.data;

Fetch measurements for all supply points

Pass every descriptor and the resolved timeframe from useTimeframe to the measurements query. The Measurements API returns one normalized measurements array for the selected property and timeframe.

_components/consumption-overview.tsx
import { useQuery } from "@tanstack/react-query";
import { measurementsQueryOptions } from "@octopus-energy/measurements/react-query";

const measurementsQuery = useQuery(
  measurementsQueryOptions(client, {
    propertyId,
    marketSupplyPoints,
    timeframe,
  }),
);

measurementsQueryOptions automatically disables the query while marketSupplyPoints is undefined, null, or an empty array. You only need to pass enabled yourself for additional product-specific conditions.

Consumption defaults

The measurements API has its own defaults for electricity reading direction. If you need generation/export data, pass readingDirections to measurementsQueryOptions.

Handle query states

If supply points are still loading, keep the Coral overview shell visible with loading set to true. If the supply point query errors, return an error state before rendering controls for a property that cannot show data.

_components/consumption-overview.tsx
if (marketSupplyPointsQuery.error) {
  return (
    <CoralError
      errorCode={marketSupplyPointsQuery.error.code}
      heading="Unable to load supply points"
      message={marketSupplyPointsQuery.error.message}
    />
  );
}

return (
  <EnergyOverview
    dateLocale={enGB}
    loading={marketSupplyPointsQuery.isPending || measurementsQuery.isPending}
  >
    {/** Timeframe controls from the previous guide. */}

    {measurementsQuery.error && (
      <CoralError
        errorCode={measurementsQuery.error.code}
        heading="Unable to load measurements"
        message={measurementsQuery.error.message}
      />
    )}
  </EnergyOverview>
);

From here, group measurementsQuery.data and pass each group to a reusable card component. See Render Usage Charts for the full rendering pattern.

Implementation checkpoint

At this checkpoint, ConsumptionOverview owns the shared timeframe, renders the Coral controls, and fetches supply point descriptors and measurements with TanStack Query.

FAQ

On this page