Skip to main content

How to use the API

The API is a REST API, and can be used similarly to other common APIs.

🔑 In order to access the routes of the API (the various functions), you need to have first an API key. More information on how to get access is provided here.

Example 1: retrieve the data and plot a performance plot​

A pull example can be downloaded here.

Retrieval of data using Python​

First, install the required packaged with pip: pip install requests plotly pandas.

Import the required packages first:

import json, requests
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

Then, specify the parameters as variables:

month = 8
day = 31
year = 2024
interval = 5 # minutes
uuid = "ff45e931-e60b-4da6-a844-0c103f2534d0" # given UUID of the plant

Access the data properly speaking​

First, we can copy directly the code block as shown on the portal itself.

url = f"https://data.solarify.ch/api/performance/interval/{uuid}/{year}/{month}/{day}/{interval}"
payload = {}
headers = {"x-api-key": "<INSERT YOUR API KEY HERE - SEE ABOVE>"}

response = requests.request("GET", url, headers=headers, data=payload)
data = json.loads(response.text)

Plot the performance plot​

In order to simplify plotting, we can convert the retrieved data as dataframe (df):

df = pd.DataFrame(data)

Then, we can proceed with plotting using the existing library plotly:

fig = go.Figure()
fig.add_trace(go.Scatter(x=df['timestamp'], y=df['p_yield'], mode='lines+markers', name='PV Production'))
fig.update_layout(title="Energy Profiles", xaxis_title=f"Time [min]", yaxis_title="Power [kW]")
fig.show()

What's next?​

Of course, this only shows you the performance curve for one specific day, and for one specific plant. You can plot and overlay several curves at once by looping through a list of UUIDs retrieved from the /plants route, or loop through all the days of a given month, or even years.

Enjoy! 🎉