Skip to content

๐Ÿ™ Octopus Energy API client written in Golang

License

Notifications You must be signed in to change notification settings

danopstech/octopusenergy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

logo

Octopus Energy Golang API client


PkgGoDev License Release tests Go Report Card GitHub go.mod Go version GitHub issues

This package provides a Golang client to Octopus Energy's API. Octopus Energy provides a REST API for customers to interact with our platform. Amongst other things, it provides functionality for:

  • Browsing energy products, tariffs and their charges.
  • Retrieving details about a UK electricity meter-point.
  • Browsing the half-hourly consumption of an electricity or gas meter.
  • Determining the grid-supply-point (GSP) for a UK postcode.

If you are an Octopus Energy customer, you can generate an API key from your online dashboard.

Authentication

Authentication is required for all API end-points when using this API client. This is performed via HTTP Basic Auth. This is configured when you instantiate a new client with a config object. Warning: Do not share your secret API keys with anyone.

Not an Octopus Energy customer?

Please read about the Octopus tariffs and ensure they are right for you, if you think they are, then please use my referral link. (at the time of writing this we will both receive ยฃ50 credit)

Usage

More in the examples folder

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

var netClient = http.Client{
    Timeout: time.Second * 10,
}

client := octopusenergy.NewClient(octopusenergy.NewConfig().
    WithApiKeyFromEnvironments().
    WithHTTPClient(netClient),
)

consumption, err := client.Consumption.GetPagesWithContext(ctx, &octopusenergy.ConsumptionGetOptions{
    MPN:          "1111111111", // <--- replace
    SerialNumber: "1111111111", // <--- replace
    FuelType:     octopusenergy.FuelTypeElectricity,
    PeriodFrom:   octopusenergy.Time(time.Now().Add(-48 * time.Hour)),
})

if err != nil {
    log.Fatalf("failed to getting consumption: %s", err.Error())
}

Links