Free · CC BY 4.0 GitHub Reddit LinkedIn

Move a whole solution, and keep it moving.

How to move a Power Platform solution from one environment to another with code, without the portal: inside one tenant, and into a different organization's tenant. Export, import, connection references, turning flows on afterwards, signing in to two tenants, and keeping two copies in sync. Every claim in the KB is marked with how sure it is.

Version 1.0 One tenant or two Built three times: PowerShell, a server, a browser extension 27 error messages decoded

Pick where it's going. Get the steps for that move.

The KB's three paths, each with the steps it takes, in the order you'd do them. Pick a step to see the request, what comes back and what goes wrong. Each step carries the mark the KB gives it.

Power Apps | Solutions › Move plan
10 steps Re-confirmedProvenUntested

Loading the paths from the KB...

Sign in

Re-confirmed

Sign in once per tenant with offline_access and keep that tenant's refresh token. Redeem it for each resource you need, changing only the scope. Inside one tenant, one sign-in covers both environments.

Inputs: one scope per resource

Dataverse (each org)https://<org>.crm<N>.dynamics.com/.default
Power Apps APIhttps://service.powerapps.com/.default
Authorityhttps://login.microsoftonline.com/organizations/oauth2/v2.0

Outputs

One refresh token mints tokens for every org in its tenant. Cache access tokens per tenant and resource, and refresh a few minutes before they expire.

The app registration

One multi-tenant app registration served both tenants, with delegated permissions Dynamics CRM user_impersonation and PowerApps Service User, consented in each tenant. Register your own; don't borrow another product's client ID.

Watch out for

  • An empty HTTP 401 from Dataverse means the token was issued for an account in a different tenant than the org's. It happened three times in testing, every time because the account picker chose the other account. After every sign-in, check that the org is in that tenant's environment list.
  • Silent sign-in with two accounts signed in fails with AADSTS16000. Pass the account's UPN as login_hint with prompt=none.
  • Device code from a browser extension fails with AADSTS9002326; redeem it on a server, or use authorization code with PKCE.
  • Untested First-time consent in a tenant that has never seen the app.
Section 2 in the KB

Prepare the receiving tenant

Proven

Before the first import into another organization's tenant, the receiving side needed all four of these. Each one came from a real error.

Needed, and the error without it

LicenseA Power Automate license for the signing-in user (a Premium trial was enough). Without it: AADSTS650052
Service principalThe Dataverse service principal, created with New-MgServicePrincipal -AppId <app id>. Without it: AADSTS650052
RoleSystem Administrator in the receiving environment. Without it: HTTP 403 naming prvCreateEntity
ConsentAdmin consent for your app registration. Without it: a consent prompt, or AADSTS65001

Watch out for

  • Untested Whether the license or the service principal alone fixes AADSTS650052; both were done.
  • AADSTS65001 also appeared when the receiving side was asked for a Graph token instead of a Dataverse token. Ask for the Dataverse scope of the receiving org.
The receiving tenant, in the KB

Find the solution and the environment

Re-confirmed

Dataverse Web API v9.2, with headers Accept: application/json, OData-MaxVersion: 4.0 and OData-Version: 4.0.

Requests

SolutionsGET solutions?$filter=ismanaged eq false and isvisible eq true&$select=uniquename,friendlyname,version
EnvironmentsGET https://api.powerapps.com/providers/Microsoft.PowerApps/environments?api-version=2016-11-01
ConnectionsGET https://api.powerapps.com/providers/Microsoft.PowerApps/connections?api-version=2016-11-01&$filter=environment eq '<envId>'

Outputs

Match an org to its environment by comparing the org host with properties.linkedEnvironmentMetadata.instanceUrl; that URL ends with a slash, so normalize both. The default environment's id is Default-<tenantId>.

Watch out for

  • Filter connections by the environment you're importing into. An early script read the default environment's connections while importing into another one, and none of 16 references could be bound.
  • Connection ids come in several formats, even within one environment, among them shared-<connector>-<guid>. Store them exactly as returned.
Section 3 in the KB

Export

Re-confirmed

The response's ExportSolutionFile is the solution ZIP, base64-encoded.

Request

POST https://<org>/api/data/v9.2/ExportSolution
{ "SolutionName": "<uniquename>", "Managed": false }

Measured Fast enough to stay synchronous

7 to 33 seconds for a 65 KB solution, so the async export (ExportSolutionAsync + DownloadSolutionExportData) was never used. Untested for large solutions.

Watch out for

  • Publish desktop flows first. Saving in the Designer writes a draft that Dataverse's workflow row doesn't show; only Publish updates it. A desktop flow then travels with its four binaries under desktopflowbinaries/<id>/.
  • A managed solution can't be exported again from where it landed: 0x80048036. Everything else here moved unmanaged solutions, which suits two copies that both get edited.
  • Failed Moving only some components by cutting folders out of the ZIP. Use a smaller solution instead.
Sections 4 and 7 in the KB

Find and pick the connections

Re-confirmed

Before the import, list every connection reference the solution uses and pick a connection for each. The import never creates connections: a connection is an OAuth sign-in, so a person creates each one once on the receiving side.

Read both places; either one alone misses some

  1. customizations.xml: <connectionreference connectionreferencelogicalname="..."> elements. The connector is a child element, <connectorid>/providers/Microsoft.PowerApps/apis/shared_office365</connectorid>, not an attribute.
  2. Each flow's JSON: properties.connectionReferences.<key>.connection.connectionReferenceLogicalName.

Pick a connection, in this order

Keep the receiving environment's connections with statuses[0].status = Connected, match on the connector name, then prefer:

  1. the connection used last time for this reference on this side,
  2. a connection created by the signed-in user (properties.createdBy.userPrincipalName),
  3. any other connected connection for that connector.

Watch out for

  • One solution had 12 references in the XML and 4 more that only appeared inside flow JSON, 16 in all.
  • Leave references that are already bound alone. An import that doesn't mention a reference keeps its binding. Only touch the solution's own references, not system ones like msdyn_Dataverse.
  • You can't unbind a reference by PATCHing connectionid to null: it answers 204 and keeps the binding.
Sections 6.1 and 6.2 in the KB

Import, binding connection references

Re-confirmed

The first import creates the solution and its publisher; nothing needs to exist on the receiving side. Pass the connection bindings in the same call.

Request

POST https://<org>/api/data/v9.2/ImportSolutionAsync
{
  "CustomizationFile": "<base64 zip>",
  "OverwriteUnmanagedCustomizations": true,
  "PublishWorkflows": true,
  "ComponentParameters": [ ...connection bindings, section 6... ]
}
"ComponentParameters": [
  {
    "@odata.type": "Microsoft.Dynamics.CRM.connectionreference",
    "connectionreferencelogicalname": "<logical name>",
    "connectorid": "/providers/Microsoft.PowerApps/apis/shared_office365",
    "connectionid": "<connection id, exactly as listed>"
  }
]

Outputs

An AsyncOperationId and an ImportJobKey. Poll GET asyncoperations(<id>)?$select=statecode,statuscode,message every 5 seconds: statecode 3 means finished, then statuscode 30 is success and 31 is failure. Per-component warnings and failures are in GET importjobs(<id>).

Watch out for

  • Some orgs refuse async imports with HTTP 405. Fall back to POST ImportSolution with the same body plus an ImportJobId (a new GUID).
  • Another import running in the org gives SolutionConcurrencyFailure. Wait about 10 seconds and retry. On HTTP 429, honor Retry-After.
  • 0x80045042, "The original workflow definition has been deactivated and replaced.", is a warning, not an error: one per cloud flow on every re-import.
  • A synchronous import from a browser extension outlives an idle service worker. A keep-alive every 20 seconds carried one through a 197-second import.
Sections 5 and 6.3 in the KB

Bind the rest, turn flows on

Re-confirmed

Don't trust the state after an import. Read which references are bound and which flows are on, bind what's unbound, then turn on the flows that are on in the source.

Requests

BindPATCH connectionreferences(<id>) with { "connectionid": "<connection id>" }
Turn onPATCH workflows(<id>) with { "statecode": 1, "statuscode": 2 }
Turn off{ "statecode": 0, "statuscode": 1 }

Which flows

Each cloud flow that is on in the source (from customizations.xml: <Category> 5, <StateCode> 1), is off here, and has all its references bound. Report anything left, with a link to the receiving environment's connections page: https://make.powerautomate.com/environments/<envId>/connections.

Measured 37 flows into another tenant

2 turned on, 13 were skipped and 22 failed, because they referred to SharePoint sites, mailboxes and AI Builder models that only existed in the source tenant. Moving the solution doesn't move the data or resources its flows use.

Watch out for

  • 0x80060467 is the answer to turning on a flow whose reference has no connection yet. Create the connection, bind it, and turn the flow on again.
  • A reference bound to a connection that was later deleted still looks bound.
Section 6.4 in the KB

Environment variables

Proven

A definition travels with the solution. Its value travels only if the value record is itself in the solution, and then the import overwrites the receiving side's value. A value that isn't in the solution never leaves the source, and the receiving side's own value is kept.

A different value per environment

Keep the values out of the solution (no environmentvariablevalues.json in the ZIP) and set each side's own: POST environmentvariablevalues with schemaname, value and "EnvironmentVariableDefinitionId@odata.bind", or PATCH an existing one.

Section 6.5 in the KB

Store the baseline

Proven

Dataverse's re-export of a solution you just imported isn't byte-identical to what you imported, so the next run sees a change and copies it straight back. After every import, export the receiving side again, hash it, and store that as its baseline. Only update baselines after an import that succeeded.

Next run

Compare each side's hash with its baseline to decide which way to copy. Try the rule below.

Section 8.2 in the KB

One run at a time

Two synchronous imports into the same org collide (SolutionConcurrencyFailure). Hold a lock per pair of environments for the whole run, with an expiry so a crashed run can't block it forever (20 minutes was used), and mark any run still "running" at startup as interrupted.

Section 8.5 in the KB

Tested with delegated (user) sign-in and unmanaged solutions, in two tenants. Nothing here was tested with a service principal.

Three findings hold on every path

The import never creates connections. It can only bind references to connections that already exist, so plan for one manual step. Don't trust the state after import. Read which flows are on and bind what's unbound. An export is never byte-identical to the last one. Hash the contents, not the ZIP.

Keep two copies in sync, without the ping-pong.

Both copies can change. You need change detection, a direction rule and a conflict rule. Section 8 of the KB; the table on the right is read from the KB file itself.

Detect a change: hash the contents

Hashing the exported ZIP always reports a change: compression output and timestamps differ on every export. Re-confirmed

  1. For every file in the ZIP's central directory, take name:crc32:uncompressedSize.
  2. Leave out the files that change on every export: solution.xml, [Content_Types].xml, customizations.xml, and everything under Entities/.
  3. Sort the lines, join them, and hash the result (SHA-256 was used).

The same solution exported from two different orgs gave the same hash. A flow edit on one side moved that side's hash only.

Blind spot: a change made only to tables or columns lives in the excluded files, so it isn't detected. The workaround was a manual "push this side" button.

Decide the direction: baselines

Proven
SituationAction
Loading the table from the KB...

Newest wins Proven

The other rule built: when the hashes differ, copy the side with the newer modifiedon over the older. 13 of 13 runs picked the right direction. The solution record's modifiedon doesn't change when you edit a flow in it, so take the latest of the solution and its flows. If either time can't be read, or they're equal, pause.

Conflicts Proven

When both sides changed, pause and let the user choose a side, which then runs as a one-way copy. Whatever rule you choose, keep the overwritten package: an import replaces unmanaged customizations, and there's no undo.

How long it takes.

One-off timings from single runs, on small test solutions unless the row says otherwise. Section 9 of the KB, read from the KB file itself. Measured

RunTime
Loading the timings from the KB...

Paste the error. Get the real cause.

All 27 symptoms 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 Apps | 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.