Dynamically Updating Piece Connections Using Customer Credentials During Flow Import from Template

Hi Activepieces team,
I’m currently working on an automation platform built on top of Activepieces (self-hosted setup), and I’d like your input regarding dynamic connection updates in the following use case:

Project Scenario:
We are building a system where users can automate workflows using two methods:

  1. Create Flow – Users create their own flows manually.
  2. Import Flow (Clone from Templates) – Users choose from 3 predefined flow templates that we’ve created. These templates involve common integrations (e.g., Salesforce and other pieces).

Once a user selects one of the templates, the process should happen automatically:
The selected flow is cloned for the user.
Piece connections within the flow should be updated to use that user’s credentials.
The user should be able to run the flow immediately without manually configuring connections.

The Challenge:
We want to automate the process of setting up connections dynamically with the user’s credentials, ideally via backend logic after the flow is cloned. I’ve looked into the Upsert Connection API and have a few questions:

Questions

  1. Can the POST /v1/app-connections API be used to dynamically create or update piece connections (e.g., OAuth2 credentials or Secret Text) for a user after a flow is cloned?
  2. What are the supported use cases for the upsert endpoint?
    Does it automatically assign the connection to the right flow/piece internally?
    Does it require any prior manual setup (e.g., connecting through the UI once)?
  3. What’s the recommended approach to:
    Clone a flow from a template
    Inject/update piece connections for a given user
    Ensure the flow is runnable immediately after being cloned
  4. Is there any way to associate or attach the updated connection with the corresponding piece programmatically, so the user doesn’t need to do anything manually?
  5. If this cannot be done fully via API, what are the other options to handle this flow seamlessly?

Thanks in advance for any help! :pray: