paragon
export from @useparagon/connect
) and public endpoints of the Paragon REST API.
For on-premise users:
If you are using an on-premise instance of Paragon, you can call the .configureGlobal
function to point the SDK to use the base hostname of your Paragon instance.
.authenticate(projectId: string, userToken: string)
.authenticate
should be called at the beginning of your application’s lifecycle in all cases. This is to make sure that the userToken
is always as fresh as possible, with respect to your user’s existing session on your own site.
JavaScript SDK
.authenticate
has been called, you can access the user’s integration state with .getUser()
. .authenticate()
only needs to be called when using the Paragon SDK - when making requests to the Paragon REST API, you should instead provide the Paragon User Token in the Authorization header.
.connect(integrationType: string, installOptions?: InstallOptions)
Call.connect
to launch your Connect Portal for a specific integration provider. You can find the integrationType
identifier you need in the Overview page for the integration.
JavaScript SDK
await
the Promise returned by #.authenticate-projectid-string-usertoken-string
to show a loading state before users are able to access the Connect Portal.
You must have an integration configured of this integrationType
in your Paragon project for the Connect Portal to appear. Otherwise, this function does nothing.
Optional `installOptions`
Optional `installOptions`
onSuccess
Callback invoked when an integration is successfully enabled.
-
onError
Callback if an unexpected error occurs. -
accountType
For integrations that support multiple account types, you can optionally designate a specificaccountType
to skip the account selection dialog.-
default
-
sandbox
-
Multi Account Authorization
.disableWorkflow(workflowId: string) -> Promise
Call.disableWorkflow
to turn off a workflow for a user by ID.
.enableWorkflow(workflowId: string) -> Promise
Call.enableWorkflow
to turn on a workflow for a user by ID.
.getDataSourceOptions(integrationType: string, sourceType: string)
Call.getDataSourceOptions
to get configuration details for compound data sources used for dynamic User Settings types in the Headless Connect Portal.
Compound data sources, for Field Mapping and Combo Dropdown inputs, have multiple data sources within them (Field Mappings have both Object Types and Field Names as sources).
To load options for a data source, see getFieldOptions
.
Arguments:
An integration type string, like
salesforce
.A source type string, which can be found in the
sourceType
property of a
User Setting object from getIntegrationConfig
or
from stage.options
of PostOptionsStage
..getFieldOptions(fieldOptions: FieldOptions)
Load options from an integration data source for dynamic User Settings types in the Headless Connect Portal, using the Connected User’s account.getFieldOptions()
can only be called for data sources with type DYNAMIC_DATA_SOURCE
(for dynamic enum input types).
-
Compound data sources like
FIELD_MAPPER_DATA_SOURCE
orCOMBO_INPUT_DATA_SOURCE
are composed ofDYNAMIC_DATA_SOURCE
-type sources. -
When rendering Field Mapping or Combo Dropdown inputs, first identify each data source with
getDataSourceOptions
, and use the returned configuration to callgetFieldOptions
with the appropriate keys. See a full example.
fieldOptions
below to learn more.
Arguments:
Show child properties
Show child properties
An integration type string, like
salesforce
.A source type string, which can be found in the
sourceType
property of a User Setting object from getIntegrationConfig
or from stage.options
of PostOptionsStage
.A user-provided search query for an option. When provided, the data source will return options that match this query.
A page cursor to use to load subsequent pages of results. The response of
getFieldOptions
will provide nextPageCursor
to use or null
if there are no more results.When loading options for a compound data source (e.g.
fieldSource
of a Field Mapping input or dependentInputSource
of a Combo Dropdown input), pass parameters with the user’s selection from the first input (e.g. the Record Type for Field Mapping).Show child properties
Show child properties
The
cacheKey
property of the primary/first input in the compound data sources (e.g. recordSource
of a Field Mapping input or mainInputSource
of a Combo Dropdown input).Show child properties
Show child properties
data
will be an Array of either Option
or Section
objects, which should be handled by your Dropdown input.- Option
- Section
The human-readable display name to use for this option when displaying
it to your user.
The unique value of this option to save with
setPreOptions
,
setPostOptions
, updateIntegrationUserSettings
, or
updateWorkflowUserSettings
. This value can also be passed as
parameters[].source.value
for dependent inputs of compound data
sources.This section is an empty array for all input types except for Default value mapping, which is only supported by Jira: Issue Field Values.
The cursor value to pass as
cursor
for the next page of results..getIntegrationConfig(integrationType: string)
CallgetIntegrationConfig
to get the user-facing descriptions, User Settings, and Workflows associated with any integration.
.getIntegrationMetadata(integrationType: string?)
Call.getIntegrationMetadata
to get the name
, brandColor
, and icon
, for any of your active integration providers. This is a great way to create your integrations page!
.getUser() → ParagonUser
Call.getUser
to retrieve the currently authenticated user and their connected integration state.
A ParagonUser is an object shaped like:
{ authenticated: false }
instead. Please check the authenticated
property before using the user.integrations
field.
.event(name: string, json: JSON)
App Events can be sent from your application using the Paragon SDK or REST API. In both cases, you must pass two parameters:- name - the event name defined in your App Event
- payload - the event payload that should match the event schema defined in your App Event
.installIntegration(integrationType: string, installOptions?: InstallOptions) -> Promise<IntegrationInstallEvent>
This function should be used only if you are using your own components to show connected integrations and their status, instead of the Connect Portal.Otherwise, you can use the
.connect
function..installIntegration
can be used to start the connection process for an integration without the Connect Portal appearing over your user interface. You can find the integrationType
identifier you need in the Overview page for the integration.
This function resolves with the IntegrationInstallEvent
in the same format available in paragon.subscribe
. You can use this to get the newly created credential by awaiting the returned Promise.
This function rejects the returned Promise if the integration is already installed for the authenticated user.
JavaScript SDK
integrationType
requires API keys or post-authentication options, the Connect Portal will still appear to capture those values from your user at that time. The Connect Portal will automatically be dismissed after those values are entered.
This function accepts the same optional install options as #.connect-integration.
.subscribe(eventName: string, handler: Function)
Call.subscribe
to subscribe to different events and changes from the Paragon SDK. You can find the possible eventNames
below:
Event Type | Usage in .subscribe() | Usage in .connect() |
---|---|---|
Integration enabled | "onIntegrationInstall" | "onInstall" |
Integration disabled | "onIntegrationUninstall" | "onUninstall" |
Workflow state change | "onWorkflowChange" | "onWorkflowChange" |
Connect Portal opened | "onPortalOpen" | "onOpen" |
Connect Portal closed | "onPortalClose" | "onClose" |
.connect()
only applies to a currently open Connect Portal locally.
See the code examples below for how to subscribe to events using the Paragon SDK.
onOpen
, onClose
, onUninstall
, and onWorkflowChange
as a one-time event locally.
.request(integrationType: string, path: string, requestOptions: RequestInit ) → Promise
Call.request
to send an API request to a third-party integration on behalf of one of your users.
Every integration in your dashboard has a code example of using paragon.request
, which takes three arguments:
-
integrationType
: The short name for the integration. i.e. “salesforce” or “googleCalendar”. You can find this string on the Overview tab of the integration you want to access, on your Paragon dashboard. -
path
: The path (without the hostname) of the API request you are trying to access. An example might be: “/v1/charges” for Stripe’s charge API or “chat.postMessage” for Slack’s Web API. -
requestOptions
: Request options to include, such as:-
body
: An object representing JSON contents of the request. -
method
: An HTTP verb such as “GET” or “POST”. Defaults to GET.
-
.setUserMetadata(meta: object)
Call.setUserMetadata()
to associate the authenticated user with metadata from your application. This metadata can be accessed with .getUser()
or retrieved over the API.
.uninstallIntegration(integrationType: string) -> Promise
Call.uninstallIntegration()
to disconnect an integration for the authenticated user.
When an integration is disconnected, workflows for that integration will stop running for the authenticated user and any saved User Settings will be cleared.
.updateIntegrationUserSettings(integrationType: string, userSettingsUpdate: object, options?: CredentialConfigOptions)
Call.updateIntegrationUserSettings()
to update any integration-level User Settings for your Connected User.
Arguments:
An integration type string, like
salesforce
.A partial update object where the keys are the
id
properties of User Settings objects (which you can get from getIntegrationConfig
) and the values are the user’s selection for the matching input type.Any keys that are not included in the object will not be updated.The type for each value will depend on the input type. See Input Types Reference to see the value type for each input.Example
Optionally specify a Credential and Configuration to target, if using Multi-Account Authorization or Multi-Configuration.
Show child properties
Show child properties
The Credential ID (a UUID) of the connected account you want to update, if using Multi-Account Authorization.
The Configuration ID (a UUID or an External ID prefixed with
ext:
), if using Multi-Configuration..updateWorkflowState(workflowStateUpdate: object, options?: CredentialConfigOptions)
Call.updateWorkflowState()
to enable or disable workflows for a user.
Arguments:
A partial update object where keys are workflow IDs and values are
true
or false
. Any workflow IDs not included in this object will not be updated in this call.Example
Optionally specify a Credential and Configuration to target, if using Multi-Account Authorization or Multi-Configuration.
Show child properties
Show child properties
The Credential ID (a UUID) of the connected account you want to update, if using Multi-Account Authorization.
The Configuration ID (a UUID or an External ID prefixed with
ext:
), if using Multi-Configuration..updateWorkflowUserSettings(integrationType: string, workflowId: string, userSettingsUpdate: object, options?: CredentialConfigOptions)
Call.updateWorkflowUserSettings()
to update any workflow-level User Settings for your Connected User.
Arguments:
An integration type string, like
salesforce
.The ID of the Workflow that the workflow-level User Setting you are modifying belongs to. If you are trying to modify an integration-level User Setting, call
updateIntegrationUserSettings
instead.A partial update object where the keys are the
id
properties of User Settings objects (which you can get from getIntegrationConfig
) and the values are the user’s selection for the matching input type.Any keys that are not included in the object will not be updated.The type for each value will depend on the input type. See Input Types Reference to see the value type for each input.Example
Optionally specify a Credential and Configuration to target, if using Multi-Account Authorization or Multi-Configuration.
Show child properties
Show child properties
The Credential ID (a UUID) of the connected account you want to update, if using Multi-Account Authorization.
The Configuration ID (a UUID or an External ID prefixed with
ext:
), if using Multi-Configuration..workflow(workflowId: string, options: FetchOptions)
Call.workflow()
to trigger a Paragon workflow that sends a custom response back to your app. Note: The workflow must be enabled and use a Request-type trigger.
Get project’s integrations
Returns a list of the integrations enabled for the Paragon project by the ID in the URL.- Includes the Connect Portal configuration for each integration (as
.configs
) and the Workflows associated with each integration (as.workflows
)
getIntegrationMetadata
and getIntegrationConfig
when using the JavaScript SDK.
REST API
Get user’s Connect credentials
Returns a list of the user’s Connect credentials (i.e., the accounts connected and authorized by the end user).- The providerId is the authenticated user’s ID assigned by their integration provider (e.g. for a Salesforce integration, this would be the user’s Salesforce user ID)
REST API
Update user’s Connect credential
Updates the user’s connected integration account, including any settings and configured workflows. This endpoint updates by replacement with respect to theconfig
property, so this endpoint should only be used after retrieving the existing value (which can be done by using the above endpoint: Get user’s Connect credentials).
Alternatively, you can use the SDK to update User Settings or workflow enablements:
updateIntegrationUserSettings
: Update integration-level User Settings.updateWorkflowUserSettings
: Update workflow-level User Settings.updateWorkflowState
: Update workflow enablements.
REST API
config
must be provided in full, with the intended changes applied. This is because config
will be updated by replacement.
installFlow
UseinstallFlow
when implementing the Headless Connect Portal to guide your user through the installation process for an integration.
installFlow.start(integrationType, options)
CallinstallFlow.start()
to begin an install flow for an integration. See an example call.
Arguments:
The integration type string, like
salesforce
.Show child properties
Show child properties
This callback is called when the install flow is ready to move to the next stage.Your app must render the appropriate UI for each stage, so that your user can provide the necessary details in that stage to connect their account.
Show callback arguments
Show callback arguments
The install flow stage for your app to render.
- AccountTypeStage
- PreOptionsStage
- PostOptionsStage
In the
AccountTypeStage
, the user should be prompted with a list of account types that they can choose from.If you want to skip this stage, pass the first account type option (or "default"
) to installFlow.setAccountType()
to move to the next stage.Example (Salesforce)
"accountType"
for AccountTypeStage.This callback is called when the install flow completes successfully.
This callback is called when the install flow fails, with an error object and error context.
Show callback arguments
Show callback arguments
The error object. You can read the
.name
of the error object to identify one of the following error types:OAuthBlockedError
: The browser blocked the OAuth prompt from appearing. This may require the user to allow popups in their browser settings.OAuthTimeoutError
: The OAuth prompt took longer thanoauthTimeout
milliseconds (as provided inoptions
) to complete.UserNotAuthenticatedError
: The user is not authenticated with the Paragon SDK. Verify thatparagon.authenticate()
has been called before starting the install flow.NoActiveInstallFlowError
: An install flow function was called, but no install flow is currently active. Callstart()
to start an install flow.HeadlessModeNotEnabledError
: Headless Connect Portal is not enabled. Callparagon.setHeadless(true)
to enable Headless mode.IntegrationNotFoundError
: The provided integration type is not found or has not been enabled in your Paragon project.
The number of milliseconds to wait for an OAuth prompt to complete. If the user does not complete the OAuth prompt within this time, the install flow will fail, and the
onError
callback will be called.If not provided, there will be no timeout for the OAuth prompt.installFlow.setAccountType(accountType)
CallinstallFlow.setAccountType(accountType)
when the user selects an account type in the AccountTypeStage
.
Arguments:
The account type to set. This should be the
id
property of the Account Type option that the user selected.installFlow.setPreOptions(values)
CallinstallFlow.setPreOptions(values)
when the user finishes providing inputs in the PreOptionsStage
.
This returns a Promise that resolves when the values are saved. Upon success, the install flow will move to the next stage and call onNext
. If there is no stage after the PreOptionsStage
, the install flow will call onComplete
.
Arguments:
The values to set for the inputs in the
PreOptionsStage
.This should be an object, where the keys are id
s of the inputs in the PreOptionsStage
, and the values are the values that the user provided for each input.Example (Shopify)
installFlow.setPostOptions(values)
CallinstallFlow.setPostOptions(values)
when the user finishes providing inputs in the PostOptionsStage
.
This returns a Promise that resolves when the values are saved. Upon success, the install flow will be completed and call onComplete
.
Arguments:
The values to set for the inputs in the
PostOptionsStage
.This should be an object, where the keys are id
s of the inputs in the PostOptionsStage
, and the values are the values that the user provided for each input.Example (Jira)
ExternalFilePicker
You can use the Paragon SDK to allow your user to select files from a File Storage integration in your app. The SDK provides anExternalFilePicker
class to load any necessary JavaScript dependencies into your page and authenticate with your user’s connected account.
Supported integrations for ExternalFilePicker
new paragon.ExternalFilePicker(integrationType, options)
Construct a new instance of an ExternalFilePicker for an integration given byintegrationType
. Any required JS dependencies do not start loading until .init
is called.
Example:
Options
-
allowedTypes
(default:undefined
)-
An array of MIME types to allow for file selection, e.g.
["application/pdf", "image/jpeg"]
-
If
undefined
, all types will be allowed.
-
An array of MIME types to allow for file selection, e.g.
-
allowMultiSelect
(default:false
)- If
true
, allow multiple files to be selected.
- If
-
allowFolderSelect
(default:false
)- If
true
, allow folders to be selected.
- If
-
onOpen()
- Called when a Picker successfully appears in the app.
-
onClose()
- Called when a Picker gets closed.
-
onFileSelect(files)
- Called when a Picker file selection is made.
-
files
is an Array of objects with the selected file objects from the 3rd-party picker script.
-
onCancel()
- Called when a Picker gets closed without any files selected.
picker.init(initConfig)
Initialize a file picker with required configurationinitConfig
. Required configuration varies per integration; see integration-specific documentation for specific details.
This function loads required JS dependencies into the page, if they have not already been loaded. Other methods, like .open
and .getInstance
, cannot be called until the Promise returned by .init
is resolved.
Example:
initConfig
also accepts selectedCredentialId
, which can be passed to select a specific account to pick files from when using Multi-Account Authorization.