So, when the user exists, the API returns an array of things (strings and bool). When the user does not exist, the API returns two strings.
This seems to be a problem when unmarshalling the API response. If I unmarshall it to a variable of array of structs, it works fine when the user exists, but when the user does not exist the unmarshalling fails.
On the other hand, when I unmarshall the response to a normal struct containing strings and bools, when the user exists, the unmarshalling fails.
Let’s say you want to read the response. What would be the struct structure so that the mapping is done correctly in both cases where the user exists and doesn’t exist.
I don’t have any experience with languages where the JSON response has to be predefined. I’d write something similar to this in Python (hacked together quickly):
import requests
token = "THETOKEN"
username = "test"
# username = "admin"
url = f"http://dev.matomo/index.php?module=API&method=UsersManager.getUser&userLogin={username}&format=JSON&token_auth={token}"
r = requests.get(url)
response = r.json()
if "result" in response:
print("An error occured:")
print(response["message"])
else:
user = response[0]
print(user["email"])