Bulk update of access profiles

Problem

Bulk update of access profiles that start with “abc*”. We have situation where some bulk access profiles need to update/patch requestable is false

Diagnosis

Tried in a different way as am good in python, developed python script to have patch activity. API we used as /v3/access-profiles/id
also do not forget to use Content-Type as application/json-patch+json

Solution

import requests


ACCESS_TOKEN = ''
TENANT_URL = ''
BASE_URL = f'{TENANT_URL}/v3/access-profiles'

HEADERS = {
    'Authorization': f'Bearer {ACCESS_TOKEN}',
    'Content-Type': 'application/json-patch+json'
}

def get_access_profiles():
    """Fetch all access profiles with pagination"""
    all_profiles = []
    url = BASE_URL

    while url:
        response = requests.get(url, headers=HEADERS)
        response.raise_for_status()
        data = response.json()

        if isinstance(data, list):
            all_profiles.extend(data)
            break
        elif isinstance(data, dict):
            all_profiles.extend(data.get('data', []))
            url = data.get('next')
        else:
            raise ValueError("Unexpected API response format")

    return all_profiles

def patch_access_profile(profile_id):
    """Enable allowAccessRequests for a given profile"""
    patch_url = f"{BASE_URL}/{profile_id}"
    patch_data = [
        {
            "op": "replace",
            "path": "/requestable",
            "value": false
        }
    ]
    response = requests.patch(patch_url, headers=HEADERS, json=patch_data)

    if response.status_code in [200, 204]:
        print(f"Patched profile ID: {profile_id}")
    else:
        print(f"Failed to patch profile ID {profile_id}: {response.status_code} - {response.text}")

def main():
    profiles = get_access_profiles()
    print(f"Total Access Profiles found: {len(profiles)}")

    for profile in profiles:
        name = profile.get('name', '')
        profile_id = profile.get('id', '')

        if name.startswith("UG_") and not profile.get('allowAccessRequests', False):
            print(f"Patching: {name} (ID: {profile_id})")
            patch_access_profile(profile_id)


if __name__ == "__main__":
    main
2 Likes

Nice! You can also use this ruby script provided by SailPoint to manage a lot of bulk loading of Entitlements, Roles, Access Profiles, Applications, etc.

1 Like

agreed! here we no need to rely on CSV file.