Free · CC BY 4.0 GitHub Reddit LinkedIn

From generated text to a running flow.

How to get a Power Automate flow from generated text to a running flow without clicking through the portal: sign in once, find the user's real resources, check the flow, deploy it, run it and read the result back. Cloud flows and desktop flows. Every claim in the KB is marked with how sure it is.

Version 1.2.1 Re-checked on PAD 2.74 (2.74.215) Cloud flows and desktop flows 32 error messages decoded

Sign in, discover, validate, deploy, run, read, fix.

The KB in the order you'd do it, laid out like a flow's run details. Pick a step to see the request, what comes back and what goes wrong. Each step carries the mark the KB gives it.

Power Automate | Run details: generated text to a running flow
8 steps Re-confirmedProvenMeasuredUnsupported

Sign in once

Re-confirmed

One device-code sign-in can serve Graph, the Flow API and Dataverse. Start it with offline_access in the scope, so a refresh token comes back.

Inputs: one scope per resource

Microsoft Graphhttps://graph.microsoft.com/.default offline_access
Flow APIhttps://service.flow.microsoft.com/.default offline_access
Dataversehttps://<org>.crm<N>.dynamics.com/.default offline_access

Outputs

A refresh token. Store it encrypted on the server, exchange it for an access token per resource with a different scope each time, and save the rotated refresh token each time.

Watch out for

  • A token the Flow API won't take gives 401. The app registration needs Flow API permissions (Flows.Manage.All, Flows.Read.All) consented.
  • .default only grants what's already consented. Discovery found 0 SharePoint sites, with no error, until Sites.Read.All was explicitly requested and consented.
  • A browser extension can't redeem a device code itself (AADSTS9002326). Run device-code start, poll and refresh on your server.
Section 2 in the KB

Discover

Re-confirmed

Give the model the user's real resources instead of letting it invent them. Models invent operation ids, site URLs and list names, and anything they invent fails at deploy time.

Requests (api-version=2016-11-01)

EnvironmentsGET https://api.powerapps.com/providers/Microsoft.PowerApps/environments
ConnectionsGET https://api.powerapps.com/providers/Microsoft.PowerApps/connections?$filter=environment eq '<envId>'
OperationsGET https://api.powerapps.com/providers/Microsoft.PowerApps/apis/shared_<connector>?$filter=environment eq '<envId>'

Outputs

Pick the environment that has properties.linkedEnvironmentMetadata.instanceUrl; that field is also its Dataverse org URL. Keep only connections whose statuses[0].status is Connected, one per connector.

Watch out for

  • The apis call fails with MissingEnvironmentFilter without the environment filter.
  • The first environment in the list isn't always the right one.
  • Inject all of a connector's operations, not a shortlist.
Section 3 in the KB

Validate

Re-confirmed

No write path checks the Robin for you. Something a paste would reject can still be written through the API, and it then fails to open and fails to run. So the Designer is the compiler.

The checks, cheapest first

  1. Static check. The Action KB's check-flows.js catches every silent-reject pattern known (107 of 107 in the probe corpus). Run it on the Action KB page.
  2. Designer paste. Paste into an empty flow and read the status bar, the error list and the action count.
  3. For flows started from the cloud, put ON ERROR only after actions that can raise errors.

Outputs

17 of 17. Everything that pasted clean also opened and ran. Everything a paste rejected or flagged failed. Paste-validation predicts API delivery exactly.

Watch out for

  • A silent reject looks clean: the canvas is empty, but the status still says Ready. Require an action count above zero.
  • A Dataverse write accepts anything; it isn't a validator.
Section 5 in the KB

Deploy the cloud flow

Re-confirmed

The deploy path in production use. The flow lands Stopped, which is deliberate: the user reviews it first.

Request

POST https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/<envId>/flows?api-version=2016-11-01
Authorization: Bearer <Flow-scoped token>
Content-Type: application/json; charset=utf-8

{
  "properties": {
    "displayName": "Invoice notification",
    "definition": { ...Logic Apps workflow definition... },
    "connectionReferences": {
      "shared_office365": {
        "connectionId": "/providers/Microsoft.PowerApps/apis/shared_office365/connections/<connectionName>",
        "connectionName": "<connectionName>",
        "id": "/providers/Microsoft.PowerApps/apis/shared_office365"
      }
    },
    "state": "Stopped"
  }
}
Turn it onPOST https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/<envId>/flows/<flowId>/start?api-version=2016-11-01
Turn it offPOST .../flows/<flowId>/stop?api-version=2016-11-01

Outputs

The response's name is the new flow's id. Starting a flow doesn't run it. It only arms the trigger.

Measured Ten long, branching flows

Written by hand with the KB's definition rules, against real resources: 9 of 10 deployed first time, and all 10 runs succeeded. The tenth read from a deliberately missing SharePoint list.

Watch out for

  • Connections need a person once. A flow created through the API gets no connections of its own; the user creates each OAuth connection once, signed in, in a browser.
  • charset=utf-8 matters. One "400 Bad Request" was only the missing charset on the content type.
  • The definition rules the API enforces, each with the exact message you get, are in the KB. Decode a message below.
Section 4 in the KB

Deliver the desktop flow

Re-confirmed

Hand the user the validated script: open an empty flow, press Ctrl+V and Publish. It always works because it's exactly what the Designer accepts. The cost is a manual step.

Watch out for

  • Remove PAD's file header lines before handing the script over: @@ConnectionString, IMPORT ... AS appmask, @SENSITIVE, @INPUT, @OUTPUT. A paste that contains them is dropped.

Unsupported Writing it straight into Dataverse

A desktop flow is a workflow row with category = 6 plus four desktopflowbinaries rows, and no person is needed. Unsupported by Microsoft: a PAD update could change any of it. Proven on one environment, with attended runs only. Try it in a test environment first.

Sections 6 and 7 in the KB

Run it

Re-confirmed

A desktop flow runs from a cloud flow, attended, over a direct-to-machine connection. A cloud flow starts from code through an HTTP request trigger.

Inputs

Desktop flowshared_uiflow / RunUIFlow_V2 with uiFlowId = the desktop flow's workflowid
Cloud flowPOST .../flows/<id>/triggers/manual/listCallbackUrl?api-version=2016-11-01

Outputs

A two-stage pipeline, generating a desktop flow and then a cloud flow that calls it, ran in 18.9 s.

Watch out for

  • Cloud-triggered runs are stricter than the Console. ON ERROR on an action that can't raise errors gives RobinPackagerValidationError; the Console still runs such a flow.
  • A manual button trigger can't be started through code: it fails with InvokerConnectionOverrideFailed.
Section 8 in the KB

Read the result

Read a desktop flow's run from the Dataverse flowsessions table, and a cloud flow's from its run history.

Requests

Desktop runGET <org>/api/data/v9.2/flowsessions?$filter=_regardingobjectid_value eq <flowId>&$orderby=createdon desc&$top=1
Cloud runsGET .../flows/<id>/runs and .../runs/<run>/actions

Outputs

Poll until the newest row after your start time leaves Running, InProgress, NotStarted, Queued or Waiting. Then read statuscode, errorcode, errormessage and errordetails.

Watch out for

  • rundetails holds only machine information.
  • PAD's logs are in C:\ProgramData\Microsoft\Power Automate\Logs, one JSON event per line, readable only from an elevated shell.
Watching the run, in the KB

Fix and redeploy

If the deploy is rejected, send the model the error message, the connection list, the failing definition (cut to about 12,000 characters) and the known-fixes list, run its answer through the same fixups, and deploy again.

Outputs

Three attempts in total is enough; more rarely helps. A deployed flow still isn't a tested flow, so run it once.

Next

Paste the error into the decoder to find its real cause in the KB's troubleshooting table.

Repair loop, in the KB

Steps without a mark are described in the KB but carry no mark of their own there.

Four ways to deliver a flow. One of them is unsupported.

Section 1 of the KB, "The delivery paths at a glance", built from the KB file itself.

Switch

OnWhat you're delivering
Control

Loading the paths from the KB...

Two findings hold across every path

Validate before you deliver. No write path checks the Robin for you. Connections need a person once. A flow created through the API gets no connections of its own, and the user has to create each OAuth connection once, signed in, in a browser.

Paste the error. Get the real cause.

All 32 error messages from the KB's troubleshooting table, each with what actually causes it and the fix. The matching runs in your browser; nothing you paste is sent anywhere.

Power Automate | Error decoder
Try

Matches

Matches the codes and wording in the table. A message the KB has never seen won't have a row; an issue on GitHub with the full error text is how new ones get added.

Watch it go from text to a running flow.

Sign in, discover, deploy, validate, run, fix.

Title card: PAD Robin Deployment KB, from generated text to a running flow
Deployment KBFrom generated text to a running flowPlays on LinkedIn.