Hello, over here again!
I want to know if there is any way to deploy widgets from API call.
curl -X POST
http://localhost:5000/api/dashboards
-H “Content-Type: application/json”
-H “Authorization: Key xxxxxxxxxxxxxxxxxxxxxx”
-d ‘{“name”: “DICCIONARIO DE DATOS”}’
Currently I am displaying the dashboard without problems, but I still can’t get something about the widgets!
I have 2 queries for the dashboad, one with a parameter and the other without a parameter.
jesse
November 8, 2021, 8:06pm
2
Technically it’s possible but it’s not documented. The easiest way to learn it is to either examine the source code for the WidgetListResource
or to open your browser’s network inspector and spy on the requests as you set up a dashboard manually.
If you’re just making copies of dashboards, you should consider using redash-toolbelt
which already has a script to do this automatically.
Great jessie, i will review the 2 ways. Actually the goal is to be able to implement the dashboard from the api call automatically.
If you have something of the json format of the first option, I would really appreciate it.
jesse:
WidgetListResource
here I leave the json example to add the widgets for api call
{“options”:{
“parameterMappings”:{},
“isHidden”:false,
“position”:{
“autoHeight”:true,
“sizeX”:3,
“sizeY”:14,
“minSizeX”:2,
“maxSizeX”:6,
“minSizeY”:1,
“maxSizeY”:1000,
“col”:0,
“row”:0}
},
“text”:"",
“width”:1,
“dashboard_id”: id_dashboad,
“visualization_id”:id_vizualitation}
thanks jessie, it is correct the information was there, in WidgetListResource.
1 Like
jesse
November 8, 2021, 10:20pm
6
Glad you found it and thank you for sharing your solution!
Hi,
Could you provide an example on how you used python to create dashboard?
Maybe I am using the wrong headers/url to send the request.
I tried a code based on redash api examples but I got 404 error for these urls:
https://somedomain.com/api/queries
Other user suggested to add “/new” at the end and now I got 500 error:
https://somedomain.com/api/queries/new
Thanks
Sure Sergio, Here I share the example of the api call with curl:
#publicar dashboards
curl -X POST
http://redash.dnslocal.com/api/dashboards
-H “Content-Type: application/json”
-H “Authorization: Key nJJsMXXXXXXXXXXXX”
-d ‘{“name”: “dashboar_name”}’
this is just to create the empty dashboard, then you must use the add widgets, you will find how to do it, in the WidgetListResource section
from flask import request
from redash import models
from redash.handlers.base import BaseResource
from redash.serializers import serialize_widget
from redash.permissions import (
require_access,
require_object_modify_permission,
require_permission,
view_only,
)
from redash.utils import json_dumps
class WidgetListResource(BaseResource):
@require_permission("edit_dashboard")
def post(self):
"""
Add a widget to a dashboard.
This file has been truncated. show original
using that example you can adapt it with python like this:
In this data science tutorial, learn about APIs by analyzing data from the international space station in this step-by-step Python API tutorial.
Est. reading time: 11 minutes
1 Like
Thank you very much, Juan.
I will try it out.