After successfully updating the metadata of one of my users using the Management API in Python, I got an error page when visiting any of my users in the Auth0 Dashboard.
The error message: “Error! Cannot use ‘in’ operator to search for ‘take’ in undefined”
I deleted all of my user profiles to try to fix but the message is still appearing and I’m not able to access profiles of new test users I create.
The python code I used to update the user meta data is below (secrets are redacted).
I would appreciate any help on this matter. Feel free to ask any clarification questions as well.
import requests
import secrets
import string
AUTH0_DOMAIN = ''
CLIENT_ID = ''
CLIENT_SECRET = ''
CONNECTION = 'Username-Password-Authentication' # or your DB connection name
TARGET_EMAIL = ''
# 1. Get Management API Token
token_url = f'https://{AUTH0_DOMAIN}/oauth/token'
token_payload = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'audience': f'https://{AUTH0_DOMAIN}/api/v2/',
'grant_type': 'client_credentials'
}
token_res = requests.post(token_url, json=token_payload)
token_res.raise_for_status()
mgmt_token = token_res.json()['access_token']
# 2. Check if user exists by email
headers = {'Authorization': f'Bearer {mgmt_token}'}
search_url = f'https://{AUTH0_DOMAIN}/api/v2/users-by-email'
search_res = requests.get(search_url, headers=headers, params={'email': TARGET_EMAIL})
search_res.raise_for_status()
users = search_res.json()
if not users:
pass
else:
user_id = users[0]['user_id']
HELLO = {"TEST1": "TEST1DATA", "TEST2": "TEST2DATA"}
update_response = requests.patch(
f'https://{AUTH0_DOMAIN}/api/v2/users/{user_id}',
headers={
'Authorization': f'Bearer {mgmt_token}',
'Content-Type': 'application/json'
},
json={
"app_metadata": HELLO
}
)
if update_response.status_code == 200:
print("User metadata updated successfully.")
else:
print("Error updating metadata:", update_response.text)```