Search code examples
apigrafanagrafana-api

Grafana API - How to switch current organization


The docs about organizations (http://docs.grafana.org/http_api/org/) use the words current and actual organization which shows that there is a kind of "active" organization which you deal with. To get "current" organization, I use:

GET /api/org

and get back:

{
    "id": 1,
    "name": "Main Org.",
    "address": {
        "address1": "",
        "address2": "",
        "city": "",
        "zipCode": "",
        "state": "",
        "country": ""
    }
}

I have created some other test organizations, but how do I switch current organization by using the Grafana API?


Tests are being done with basic auth and the default administrator user (admin:admin). I notice that if I use the UI, the current organization is changing.

enter image description here

GET /api/org

now returns:

{
    "id": 2,
    "name": "organization_test_2",
    "address": {
        "address1": "",
        "address2": "",
        "city": "",
        "zipCode": "",
        "state": "",
        "country": ""
    }
}

Solution

  • With basic auth and username admin and password admin:

    curl -X POST http://admin:admin@localhost:3000/api/user/using/<id of new org>

    Docs for switching org: http://docs.grafana.org/http_api/user/#switch-user-context