How to create API token automatically?

Hi there,

I’m trying to find a way to programatically create API tokens for various organizations. I’ve read through the following Github issues:

https://github.com/grafana/grafana/issues/2431
https://github.com/grafana/grafana/issues/2218#issuecomment-117041541
https://github.com/grafana/grafana/issues/1789

So it appears you can use basic auth to authenticate to the API. However, is there a way to generate an API token after using Basic Auth?

See this answer: How to get the API key from REST API or other scripts?

Hi, the solutions works fine, but is it possible to define orgID or orgName where it will create the API key?

Something like this

curl -X POST -H "Content-Type: application/json" -d '{
  "name": "mykey",
  "role": "Admin",
  "orgID": 2
}' http://admin:youradminpassword@community.grafana.com/api/auth/keys

Cause right now, the API key was generated only to the default Org, but what if I have multiple organization? How will I push to create the API to specific org.