I've used the Metabase API before so have a rough idea of what I'm doing, but I'm now trying to use it for a cloud instance instead of one on-prem and I'm having some issues getting JSON back rather than XML
I'm using Python and the requests
module -- a selection of the code is below with the sensitive info redacted:
import json
import requests
mb_conn = MetabaseConnector()
class MetabaseConnector(object):
def __init__(self):
self.base_url = 'http://mydomain.net/api/'
self.__api_key = KEY
self.__api_secret = SECRET
self.__auth_token = None
print('Signing in...')
sign_in_response = self.sign_in()
print(sign_in_response.text)
self.__auth_token = json.loads(sign_in_response.text)['id']
@property
def auth_token(self) -> str:
return self.__auth_token
@property
def request_headers(self) -> dict:
if self.auth_token is None:
return {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
else:
return {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Metabase-Session': self.auth_token
}
def sign_in(self) -> requests.Response:
"""
https://www.metabase.com/docs/latest/api-documentation.html#post-apisession
"""
endpoint = 'session'
body = {
'username': self.__api_key,
'password': self.__api_secret
}
return requests.request(
method='POST',
url=self.base_url + endpoint,
headers=self.request_headers,
data=json.dumps(body)
)
This works on an on-prem instance and prints the {"id": "session-key"}
like I expect, but running this on a cloud instance brings back XML data without the id
JSON hidden anywhere
Our instance is redirecting traffic to use HTTPS which I think is causing the issue -- when I change http
to https
for the on-prem API calls I get the same behaviour (XML instead of JSON)
Is there something that I could do to get the API requests to work, or would we have to disable the HTTPS redirects?
EDIT
I'll add that I'm not just getting back the "API data" formatted as XML rather than JSON, I'm getting some webpage XML back instead (the XML I'd get through my web browser)