When to Use
- Build a fully custom integration UI matching your application design
- Implement connection flows without pre-built components
- Manage configurations programmatically in vanilla JavaScript or any framework
- Need granular control over the user experience
Prerequisites
Before using the JavaScript SDK:- Create a Linked Account for your user using the Node.js SDK or API
- Generate a Session Token using the Node.js SDK or API
Installation
Install the SDK using npm or include it directly in your browser.- npm
- Browser (CDN)
Upgrading from
@cobaltio/cobalt-js? The JavaScript SDK has been renamed to @refoldai/refold-js (now major version 10). To upgrade:- Install the new package and remove the old one:
npm install @refoldai/refold-js - Update imports:
import { Cobalt } from "@cobaltio/cobalt-js"becomesimport { Refold } from "@refoldai/refold-js" - Rename the client:
new Cobalt(...)becomesnew Refold(...)
Initialization
Import and initialize the SDK with your session token.Methods
.getApp()
.getApp()
Returns application details for enabled applications. Use this to display available integrations to your users.Returns: Example Response:Use Case: Build an integrations catalog page showing all available applications.
Application identifier. Omit to retrieve all enabled applications.
Promise<Application | Application[]>.connect()
.connect()
Initiates the authentication flow for an application. For OAuth apps, opens a popup window. For API key apps, saves the provided credentials.Returns: Use Case: Add a “Connect” button to each integration card.
Application identifier (e.g.,
slack, hubspot).Authentication credentials for API key-based applications. Not required for OAuth apps.
Promise<boolean> - true if connection succeedsFor OAuth applications, the SDK handles the entire OAuth flow including popup management and token exchange.
.disconnect()
.disconnect()
Disconnects an application and removes all associated data including credentials and configurations.Returns: Use Case: Add a “Disconnect” option in your integration settings.
Application identifier to disconnect.
Promise<boolean> - true if disconnection succeeds.config()
.config()
Retrieves or creates a configuration for the linked account. Returns available workflows, settings fields, and current values.Returns: Example Response:Use Case: Build a settings page for users to configure their integration.
Configuration options.
Application identifier.
Unique identifier for this configuration. Defaults to
linked_account_id if not provided.Dynamic labels for field mapping. Used with map-type fields.
Promise<ConfigResponse>.updateConfig()
.updateConfig()
Updates configuration values including field settings and workflow states.Returns: Use Case: Save user configuration changes.
Configuration update payload.
Application identifier.
Configuration identifier.
Map of field IDs to their values.
Array of workflow configurations.
Workflow identifier.
Enable or disable the workflow.
Map of workflow field IDs to their values.
Promise<ConfigResponse> - Updated configurationComplete Example
This example demonstrates a full integration page with connection management and configuration.Troubleshooting
Authentication Errors
Authentication Errors
| Problem | Solution |
|---|---|
| ”Invalid token” error | Generate a new session token. Tokens expire after 24 hours. |
| Token not working after page refresh | Store the token and reinitialize the SDK on page load, or fetch a new token from your backend. |
| OAuth popup blocked | Ensure .connect() is called in response to a user action (click). Browsers block popups not triggered by user interaction. |
Connection Issues
Connection Issues
| Problem | Solution |
|---|---|
| OAuth popup closes without completing | Check browser popup settings. Ensure your domain is whitelisted in the Refold dashboard. |
| API key connection fails | Verify credentials are correct. Check the application’s required fields in the dashboard. |
reauth_required: true in response | The user’s credentials have expired. Call .connect() again to re-authenticate. |
Configuration Errors
Configuration Errors
| Problem | Solution |
|---|---|
| Field options not loading | Ensure the user is connected to the application before calling .config(). |
field_errors in config response | Check that all required fields have valid values. Review the error messages for specific issues. |
| Workflow not triggering | Verify enabled: true is set in the workflow configuration. |
What’s Next
- React SDK for pre-built components in React applications
- NodeJS SDK for backend operations and workflow triggers
- Auth Flows to understand different authentication methods
- Config API Reference for detailed parameter documentation