I don't have permission to the data when I GET the history of my print with REST API

I want to use python and rest api to get data form my printer and store it in a database (panda dataframe). For this I use Octoprint and Python (Pycharm).
I can retrieve the current state of the nozzle temperature with this command:

import requests
import pandas as pd
api_key = 'Here I fill in my API KEY'
url = f"http://localhost:5000/api/printer/tool?apikey={api_key}"
response = requests.get(url)
data = response.json()
df = pd.json_normalize(data)
print(df)

but when I use url = f""http://localhost:5000/api/printer?history=true?apikey={api_key}"]
I get the error: You don't have the permission to access the re...
I want the data history so I can do some data analysis.

Do I need to fill in my username and password somewhere? Or is there another solution?

By the way, my API KEY works, because if I don't use the key, I don't get any data.

Thanks for the help!

When using query parameters on the URL you can only have one ?.

Your URL needs to be like this: http://localhost:5000/api/printer?history=true&apikey={api_key} with the & to specify more than one parameter.

Ideally you would use the X-Api-Key header, rather than query parameters for a secure application.

1 Like

Thanks!! This was indeed the solution