Documentation

Embed

Programmatic Filtering-Python Code Example

Full code example for programmatic filtering using Python


#!/usr/bin/env python3

import requests
import base64
import json

api_host = "https://api.domo.com"

embed_host = "https://public.domo.com"

access_token_url = api_host + "/oauth/token?grant_type=client_credentials&scope=data%20audit%20user%20dashboard"

embed_token_url = api_host + "/v1/stories/embed/auth"
embed_url = embed_host + "/embed/pages/"

# Replace the string below with your encoded passphrase
usrPass = ""
b64Val = base64.b64encode(usrPass.encode('utf8'))

response = requests.get(access_token_url, 
                        headers={"Authorization": "Basic %s" % b64Val.decode('utf8'),
                                 "Accept": "*/*"})
auth_response = json.loads(response.text)
access_token = "Bearer %s" % auth_response['access_token']
# print(access_token)

# Replace the string below with the 5 character embed page id
embed_id = ""
payload = {"sessionLength":1440, 
           "authorizations":[{"token": embed_id, 
                              "permissions":["READ",
                                             "FILTER",
                                             "EXPORT"], 
                              "filters": []}
                            ]
           }
response = requests.post(embed_token_url, 
                         headers={"Authorization": access_token, 
                                  "Accept": "application/json", 
                                  "Content-Type": "application/json"}, 
                         data = json.dumps(payload))
# print(response.text)

embed_response = json.loads(response.text)

index_html = '''<html>
<body>
<form id="form" action="https://public.domo.com/embed/pages/{}" method="post">
<input type="hidden" name="embedToken" value="{}">
</form>
<script>document.forms[0].submit();</script>
</body>
</html>'''.format(embed_id, embed_response['authentication'])

# print(index_html)
with open("index.html", "w") as f:
    f.write(index_html)