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
customizations.xml: <connectionreference connectionreferencelogicalname="..."> elements. The connector is a child element, <connectorid>/providers/Microsoft.PowerApps/apis/shared_office365</connectorid>, not an attribute.
- 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:
- the connection used last time for this reference on this side,
- a connection created by the signed-in user (
properties.createdBy.userPrincipalName),
- 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