How can I get the dashboards of an specific organization using the API? It seems that the search endpoint does not offer a parameter to specify the organization.
Is there a way to get all the dashboard of an organization?
The example below works but it only returns the dashboards of a particular organization.
import requests
url = "https://dashboard.domain.tld/api/search?type=dash-db&limit=5000&sort=name_sort"
payload = {}
headers = {
'Accept': 'application/json',
'Authorization': 'Bearer glsa_xxxxxxxxxxxxxxxxxxxxxxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
Were you able to get an answer for this. I am stuck at the same issue.
We solved the issue, if I remember correctly, you need to select the organization using the header x-grafana-org-id. Here is the code for airflow.
def trigger_dashboard_harvest_dashboards(**context): #grafana
dashboard_authorization = Variable.get("dashboard_authorization")
dashboard_password = Variable.get("dashboard_password")
dashboard_username = Variable.get("dashboard_username")
dashboard_url = Variable.get("dashboard_url")
dashboard_org_nice_name = context['dag_run'].conf['LabName']
dashboard_org_id = context['dag_run'].conf['LabSlug']
dashboard_resource_list = {"DASHBOARD":[]}
# Encodes username
input_string = dashboard_username + ":" + dashboard_password
encoded_bytes = base64.b64encode( input_string.encode('utf-8') )
dashboard_basic_auth = encoded_bytes.decode('utf-8')
payload = {}
headers = {
'Accept': 'application/json',
'Authorization': 'Basic {dashboard_basic_auth}'.format( **{"dashboard_basic_auth":dashboard_basic_auth} )
}
# Get id of organization
url = f"{dashboard_url}/api/orgs/name/{dashboard_org_id}"
response, result = request_handler("GET", url, headers=headers, data=payload, valid_statuses=[200])
org_id = response.json()["id"]
# Needed because of x-grafana-org-id
headers = {
'Accept': 'application/json',
'x-grafana-org-id': '{id}'.format( **{"id":org_id} ),
'Authorization': 'Basic {dashboard_basic_auth}'.format( **{"dashboard_basic_auth":dashboard_basic_auth} )
}
# Get list of dashboards
url = dashboard_url + "/api/search?type=dash-db"
response, result = request_handler("GET", url, headers=headers, data=payload, valid_statuses=[200])
for dashboard in response.json():
resource_name = str(dashboard["title"])
resource_type = "DASHBOARD"
this_dashboard_url = str( dashboard["url"] )
resource_url = f"{dashboard_url}{this_dashboard_url}?orgId={org_id}"
resource_embed_url = ""
resource_original_id = str(dashboard["id"])
# Get more details of dashboard
dashboard_uid = dashboard["uid"]
url = f"{dashboard_url}/api/dashboards/uid/{dashboard_uid}"
response, result = request_handler("GET", url, headers=headers, data=payload, valid_statuses=[200])
# if dashboard is shared get the public link
if response.json()["meta"]["publicDashboardEnabled"] == True:
url = f"{dashboard_url}/api/dashboards/uid/{dashboard_uid}/public-dashboards"
response, result = request_handler("GET", url, headers=headers, data=payload, valid_statuses=[200])
access_token = response.json()["accessToken"]
resource_embed_url = f"{dashboard_url}/public-dashboards/{access_token}"
return