Script to Enable externalUser Flag to True

import requests

# Reltio URLs
RELTIO_AUTH_URL = 'https://auth.reltio.com/oauth/token'
RELTIO_USER_URL = 'https://auth.reltio.com/oauth/users/{username}'

# Authentication (Client Credentials Flow)
def get_access_token(client_id, client_secret):
token_url = RELTIO_AUTH_URL
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.post(token_url, data=data, headers=headers)
response.raise_for_status()
return response.json()['access_token']

# Get user definition from Reltio
def get_user_definition(username, access_token):
url = RELTIO_USER_URL.format(username=username)
headers = {'Authorization': f'Bearer {access_token}'}
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()

# Update the user with externalUser flag set to TRUE
def update_user_external_flag(username, access_token, user_definition):
# Set externalUser flag to TRUE
user_definition['externalUser'] = True

url = RELTIO_USER_URL.format(username=username)
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}

response = requests.put(url, json=user_definition, headers=headers)
response.raise_for_status()
return response.json()

# Main function to process a list of users
def update_external_flag_for_users(client_id, client_secret, usernames):
# Step 1: Get Access Token
access_token = get_access_token(client_id, client_secret)

# Step 2: Process each user in the list
for username in usernames:
try:
# Get the user definition
user_definition = get_user_definition(username, access_token)

# Update the externalUser flag
updated_user = update_user_external_flag(username, access_token, user_definition)

print(f"User {username} updated successfully with externalUser flag set to TRUE.")

except requests.HTTPError as e:
print(f"Failed to update user {username}: {e}")

# Example usage
if __name__ == '__main__':
client_id = '<your_client_id>'
client_secret = '<your_client_secret>'
usernames = ['user1', 'user2', 'user3'] # Replace with actual usernames

update_external_flag_for_users(client_id, client_secret, usernames)
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.