Create and use API key on Grafana startup

What I am looking to achieve is, that on startup of Grafana on a system, I want to create an API key automatically, and be able to store this in environment variables on my system.

Then, when I use a post request to create a dashboard (which I always do later in startup of the system), I want to retrieve this key and use it to have permission to create the dashboard.

They seem to just have updated it from api/keys to api/serviceaccounts, and there is not as much documentation or previous questions on this.

How would you go about achieving this?

How do you define the above? What startup are you referring to

Running/Launching Grafana.

Gotcha. So launching it via a browser? Let’s say that is doable, then how would you go about accessing the key when trying to do POST?