GitHub user dosubot[bot] added a comment to the discussion: Deck.gl map change
style directly on dashboard
<!-- Answer -->
To write a Python function to call the API endpoint
`/api/v1/dashboard/import/`, you can use the `requests` library to send a POST
request with the necessary form data. Here's an example function:
```python
import requests
import json
from io import BytesIO
def import_dashboard(api_url, dashboard_export, auth_token, passwords=None,
overwrite=False, ssh_tunnel_passwords=None, ssh_tunnel_private_keys=None,
ssh_tunnel_private_key_passwords=None):
# Prepare the data to be sent in the form of a file
buf = BytesIO()
buf.write(json.dumps(dashboard_export).encode())
buf.seek(0)
# Prepare the form data
form_data = {
"formData": (buf, "dashboard_export.zip"),
"passwords": (None, json.dumps(passwords) if passwords else ""),
"overwrite": (None, str(overwrite).lower()),
"ssh_tunnel_passwords": (None, json.dumps(ssh_tunnel_passwords) if
ssh_tunnel_passwords else ""),
"ssh_tunnel_private_keys": (None, json.dumps(ssh_tunnel_private_keys)
if ssh_tunnel_private_keys else ""),
"ssh_tunnel_private_key_passwords": (None,
json.dumps(ssh_tunnel_private_key_passwords) if
ssh_tunnel_private_key_passwords else ""),
}
# Set the headers, including the authorization token if needed
headers = {
"Authorization": f"Bearer {auth_token}",
}
# Send the POST request
response = requests.post(f"{api_url}/api/v1/dashboard/import/",
files=form_data, headers=headers)
# Check the response
if response.status_code == 200:
return response.json()
else:
return {"error": response.status_code, "message": response.text}
# Example usage
api_url = "http://your-superset-instance.com"
dashboard_export = {"your": "dashboard data"} # Replace with actual dashboard
export data
auth_token = "your_auth_token" # Replace with actual token if needed
result = import_dashboard(api_url, dashboard_export, auth_token)
print(result)
```
This function prepares the dashboard export data, sends it as a multipart
form-data POST request to the specified API endpoint, and returns the response.
Adjust the `api_url`, `dashboard_export`, and `auth_token` as needed for your
specific use case
<sup>[[1]](https://github.com/apache/superset/blob/master/tests/integration_tests/dashboards/api_tests.py)</sup>.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
---
<sup>Help Dosu learn! Give it feedback: [Great
Response](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=great_response)
| [Irrelevant
Answer](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=irrelevant_answer)
| [Incorrect
Sources](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=incorrect_sources)
| [Too
Verbose](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=hallucination)
| [Bug
Report](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/ed8c3b33-c951-4e8b-9950-390c14e09e73?feedback_type=other)</sup>
GitHub link:
https://github.com/apache/superset/discussions/32149#discussioncomment-12789020
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]