There is not a single API call that will walk up the hierarchy for you. But both Power Automate and the Graph API can retrieve a given user's Manager. Screenshot of the Get Manager action in Power Automate under the O365 Users category below:
To walk up the hierarchy, start by Initialize a variable
of type string named something like lookupManager
and set its initial value to be the current/chosen/selected user. Then Initialize a variable
of type Arrary named something like managerChain
. Then create a Do until
loop set to run until lookupManager
is null. Inside that loop, execute the Get Manager with the lookupManager
as the input. If that action returns Success, then set foundManager
to the newly found manager and also append it to your managerChain
. In a parallel branch if the Get Manager action failed, then set foundManager
to null
which will cause the loop to stop.