I’m building something using the octopus agile tariff API. My code downloads a structure from the API with the price per kWh of electricity. However, the energy costs are in a structure with fields and when I try to index the value_inc_vat
column, I only get the first result. How do I retrieve the entire column?
clc
current_date = string(datetime('today','Format','uuuu-MM-dd'))
yesterdays_date = string(datetime('yesterday','Format','uuuu-MM-dd'))
api_url = append('https://api.octopus.energy/v1/products/AGILE-24-04-03/electricity-tariffs/E-1R-AGILE-24-04-03-C/standard-unit-rates/?period_from=', yesterdays_date ,'T22:00Z&period_to=' , current_date ,'T23:59Z');
api_call = webread(api_url)
costs = api_call.results
value_inc_vat = api_call.results.value_inc_vat
To get all of a field’s values from a struct array as a single array you need to group the outputs with square brackets
value_inc_vat = [api_call.results.value_inc_vat];
Use:
costs = {api_call(:).results.value_inc_vat}'
1