In my previous post, Power Apps Code Apps – Trigger a Power Automate Flow, I walked through adding and calling a cloud flow from a code app.

On a different project, I hit an authorization error running npx power-apps list-flows. Lets look at what caused it and the two commands that fixed it.

Reason :

  • I ran npx power-apps list-flows in a code app folder to find the flow ID before adding it. The command failed with an authorization error instead of listing the flows in the environment.
  • At this point I already had a valid pac auth session. Running pac auth list showed the correct account and environment. That is what threw me.
  • The pac CLI and the npx power-apps CLI look similar, but they do not share the same signed-in identity.

Note: Per the official docs, npx power-apps authentication is independent of pac auth. Signing in with one does not sign you in to the other. See Sign in and manage accounts with the Power Apps CLI.

  • The npx power-apps CLI reads the target environmentId from the project’s power.config.json.
  • In my case, the power-apps CLI still held a stale identity from another tenant. That account did not have access to the target environment, so every npx power-apps command failed with the authorization error.

Fix :

The fix is two commands. Lets sign out of the power-apps CLI, then sign back in with the account that has access to the target environment.

  • Sign out of all accounts in the power-apps CLI cache.
npx power-apps logout
  • Sign in again. A browser window opens for interactive login.
npx power-apps login
  • Now re-run the original command. list-flows returns the solution-aware flows in the environment as expected.

Things Worth Knowing

  • The power-apps CLI picks the target environment from the current folder’s power.config.json. There is no separate set-env command. So even after a clean login, the authorization error comes back if the signed-in account has no access to that environment ID. Fix the account, or fix the environment ID. Not both at once.
  • The npm-based power-apps CLI is the recommended path for Power Apps Code Apps going forward. The pac code commands remain for other Power Platform work.

📖 Official documentation: Sign in and manage accounts with the Power Apps CLI

🙂

Leave a Reply

Discover more from Rajeev Pentyala – Technical Blog on Power Platform, Azure and AI

Subscribe now to keep reading and get access to the full archive.

Continue reading