UDM HTTP REST API

7.7. UDM HTTP REST API#

The content about the UDM HTTP REST API moved to another document. Except for the section about API clients, continue reading at UDM HTTP REST API in Nubus Customization and Modification Manual 1.x [3].

See also

For an architectural overview, see UDM HTTP REST API in Univention Corporate Server 5.2 Architecture [4].

7.7.1. API clients#

The following API clients implemented in Python exist for the UDM HTTP REST API:

  • python3-univention-directory-manager-rest-client:

    Every UCS system has it installed by default. You can use it the following way:

    Listing 7.4 Example for using Python UDM HTTP REST API client#
    from univention.admin.rest.client import UDM
    
    uri = 'https://ucs-primary.example.com/univention/udm/'
    udm = UDM.http(uri, 'Administrator', 'univention')
    module = udm.get('users/user')
    
    # 1. create a user
    obj = module.new()
    obj.properties['username'] = 'foo'
    obj.properties['password'] = 'univention'
    obj.properties['lastname'] = 'foo'
    obj.save()
    
    # 2. search for users (first user)
    obj = next(module.search('uid=*'))
    if obj:
        obj = obj.open()
    print('Object {}'.format(obj))
    
    # 3. get by dn
    ldap_base = udm.get_ldap_base()
    obj = module.get('uid=foo,cn=users,%s' % (ldap_base,))
    
    # 4. get referenced objects e.g. groups
    pg = obj.objects['primaryGroup'][0].open()
    print(pg.dn, pg.properties)
    print(obj.objects['groups'])
    
    # 5. modify
    obj.properties['description'] = 'foo'
    obj.save()
    
    # 6. move to the ldap base
    obj.move(ldap_base)
    
    # 7. remove
    obj.delete()
    
  • python3-univention-directory-manager-rest-async-client:

    After installing the Debian package on a UCS system, you can use it in the following way:

    Listing 7.5 Example for using Python asynchronous UDM REST API client#
    import asyncio
    from univention.admin.rest.async_client import UDM
    
    uri = 'https://ucs-primary.example.com/univention/udm/'
    
    async def main():
        async with UDM.http(uri, 'Administrator', 'univention') as udm:
            module = await udm.get('users/user')
    
            # 1. create a user
            obj = await module.new()
            obj.properties['username'] = 'foo'
            obj.properties['password'] = 'univention'
            obj.properties['lastname'] = 'foo'
            await obj.save()
    
            # 2. search for users (first user)
            objs = module.search()
            async for obj in objs:
                if not obj:
                    continue
                obj = await obj.open()
                print('Object {}'.format(obj))
    
            # 3. get by dn
            ldap_base = await udm.get_ldap_base()
            obj = await module.get('uid=foo,cn=users,%s' % (ldap_base,))
    
            # 4. get referenced objects e.g. groups
            pg = await obj.objects['primaryGroup'][0].open()
            print(pg.dn, pg.properties)
            print(obj.objects['groups'])
    
            # 5. modify
            obj.properties['description'] = 'foo'
            await obj.save()
    
            # 6. move to the ldap base
            await obj.move(ldap_base)
    
            # 7. remove
            await obj.delete()
    
  • Python UDM HTTP REST API Client: