How to map Nextcloud Internal Usernames to LDAP usernames?

I’m developing a python script that uses the OCS API (via a Python API Wrapper GitHub - svierne/nextcloud-API: NextCloud OCS API for Python) to automate certain stuff (creation of folder structures, sharing these with users, setting certain permissions, etc…).

The script worked fine until I enabled the “LDAP user and group backend” and tried to authenticate as a user from the LDAP. In the meantime I figured out that Nextcloud creates internal usernames which it maps to the LDAP user names to avoid the possibility of ID collisions.

This is for me a problem, as my external script somehow needs to map the LDAP user names (which I know) to the internal user names (which I do not know). The only option I am aware of is querying the database, which I do not really want to do.

So is there a different way how I can query the internal username from the outside!? Is there, for instance, an API that would allow to do this which I am not aware of…?