How to access project app-connections from a piece at runtime

:wave: Hi

I’m working on a custom piece (trigger/action) and I’d like it to automatically use a connection at execution time, without showing any connection dropdown to the user in the flow builder.

Our setup:

  • We upsert the connection via API (one per project, tied to the piece).
  • At runtime, we want the piece to fetch and use that connection based on the project context.

I came across this topic on the forum, which seems related.
However, I’m not sure how to apply the suggested approach to our case — we don’t have a previous step returning the connection, and we’re not using the builder UI to let users pick one.

Is there a clean way for a piece to retrieve the project’s connection directly at runtime?

Thanks in advance for any help! :pray:


(I saw something about the ConnectionsManager from community framework, but not sure about it)

Hi

You can use the combination of connection pieces where you can read the connection using it’s external id.

In the piece you can click on (f) on the connection field and specify the output of connections piece step

Just to confirm, from our custom piece, through the context, we call the connections.get(..) with an external name ?

this external name should be the same value for every project, and will be provided on app connections upsert

EDIT:
I tried to use context.connections, but it doesn’t exist :x:
I’m using a self-hosted in community version (I wonder if its a feature only available for enterprise version)

Hi there context.connections won’t get printed in the logs if that’s what you are basing your analysis on, though connections,get(connectionExternalId) does work.

(seen with Abdul) a quick summary of a conversation I had with the Activepieces team regarding our use case

Thanks again for the quick response of the Activepieces team :pray:


Our objective

We are building a custom piece (trigger) that needs to automatically use a connection at runtime, without showing a dropdown in the flow builder UI.


Our flow

  • On our side (Sellsy), we create a project and user for our customer.
  • We upsert an app connection via API (one per customer), with a unique externalId.
  • The customer can import and use a flow template, and is redirected to the Activepieces builder.
  • We want this integration to be as seamless as possible ; no manual connection selection by the final user.

Informations

  • When using PieceAuth.CustomAuth, the builder forces the user to select a connection (even if we provide a default value).
  • However, context.connections.get(...) only works inside run() methods of Actions (not Triggers).
  • Inside onEnable() (used in our custom trigger to register a webhook), connections are not exposed by default.
  • Using context.auth is possible in onEnable() only if the user selected a connection manually (which we want to avoid).
  • A solution would be to allow access to context.connections in onEnable() — which is not yet implemented.

Next Steps

  • We were advised to use PieceAuth.None() to hide the auth dropdown, while still managing connection access via code.
  • To unblock our case, the team has opened a PR to allow using the ConnectionsManager in onEnable/onDisable: PR #7445
  • A more complete solution is planned via the feature: Predefined Connections: Issue #7447
1 Like

Many thanks for the summary :pray:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.