Unable to export flow with a GA account
When trying to export a flow with the admin parameter with this line:
m365 flow export --id $flow.name --environment $env.name --format json --path $path
I get the following error:
Error: The caller with object id '9987b9fb-0c85-48f6-####-#########' does not have permission for connection '0a6a858c-d643-46bd-####-#########' under Api 'shared_logicflows'.
On some environments it does work, but I keep getting these errors in the default environments.
PS, the line is used within this script: https://www.cloudappie.nl/search-flows-connections/
I'll pick this up as I do have access to the env.
@JPvdB is this on the public cloud?
@waldekmastykarz yes public tenant (reproduced in two different tenants)
Seems like an API change. Is there another API that we could use instead?
@waldekmastykarz I am looking in different api versions (might be dependant on when the env. is created) not 100% sure yet but feel like I am getting close.
Okey so a few checks:
-
it is not related to when an env is created; In the tenant we see no relation between (a env. created is 2016 and 2018 throws an error, while other envs created at the exact same date seems to work.
-
One env created in Preview (US) other one Europe. Other Europe envs seems to be working.
-
The error states that object id (the user ID) has no permissions for a flow, it looks like that is for the export of the flow itself (so listing the env has no problems).
-
It could be that on https://github.com/pnp/cli-microsoft365/blob/main/src/m365/flow/commands/flow-export.ts line 66 the
https://api.bap.microsoft.comshould be replaced with${this.resource}as we did for #2398 (fix in #2399) -
It could also be that we need an
adminflag in exporting a flow as when i check the UI with FIddler it passes in the following URL:https://api.flow.microsoft.com/Providers/Microsoft.ProcessSimple/**scopes/admin**/environments/guid/flows/guid/connections?api-version=2016-11-01-beta
Will try to run some tests with code changes this weekend.
Okey might not be related to our scripts, will check tomorrow with @JPvdB. In our test tenant the flows that can not be exported all seems to be having this issue: https://powerusers.microsoft.com/t5/General-Power-Automate/caller-does-not-have-permission-for-connection-under-Api-shared/td-p/264133 (as in as soon as a connection is corrupt we cannot export the whole flow).
One step further, turns out we have same issue with Export-PnPFlow, using that against the same flow returns
Export-PnPFlow : {"error":{"code":"ConnectionAuthorizationFailed","message":"The caller with object id '9987b9fb-0c85-48f6-93ee-xxxx'
does not have permission for connection '0fc566c8-9118-4480-9b02-xxxx' under Api 'shared_logicflows'."}}
At line:1 char:1
+ Export-PnPFlow -Environment 77b8cabf-0549-48fb-85dd-xxx -Ide ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Export-PnPFlow], HttpRequestException
+ FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PnP.PowerShell.Commands.Graph.ExportFlow
I did attach the debugger to the env and it all fail when calling flows that either do not have an owner or have corrupted connections. In order to do anything in the UI (export them from UI) you also have to explicilty add yourself as an owner or resolve the connections. I am affraid that we cannot do anything about this from a script perspective (I will update the script sample to prevent potential double errors as we now also throw errors when the file could not be downloaded, opened or deleted (so when we have a flow issue we throw 3 additional errors, that does not make things clearer :-)). Expect update in a few minutes.
One step further, turns out we have same issue with
Export-PnPFlow, using that against the same flow returnsExport-PnPFlow : {"error":{"code":"ConnectionAuthorizationFailed","message":"The caller with object id '9987b9fb-0c85-48f6-93ee-xxxx' does not have permission for connection '0fc566c8-9118-4480-9b02-xxxx' under Api 'shared_logicflows'."}} At line:1 char:1 + Export-PnPFlow -Environment 77b8cabf-0549-48fb-85dd-xxx -Ide ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Export-PnPFlow], HttpRequestException + FullyQualifiedErrorId : System.Net.Http.HttpRequestException,PnP.PowerShell.Commands.Graph.ExportFlowI did attach the debugger to the env and it all fail when calling flows that either do not have an owner or have corrupted connections. In order to do anything in the UI (export them from UI) you also have to explicilty add yourself as an owner or resolve the connections. I am affraid that we cannot do anything about this from a script perspective (I will update the script sample to prevent potential double errors as we now also throw errors when the file could not be downloaded, opened or deleted (so when we have a flow issue we throw 3 additional errors, that does not make things clearer :-)). Expect update in a few minutes.
I do apologize if this is the not correct place to ask this question, but as an admin who wants to export every single flow. Would I need to take ownership of every flow and make sure I have access to every connection used in the flow?
Since we don't have an --asAdmin flag for this command, you will need ownership of the flow to export it indeed. I'm not sure if there's a way for us to perform this operation in admin mode. I could have a look at it but I have doubts.