Cobalt provides a series of endpoints and SDK functions that allow you to build the journey for your customers to connect your platform with the third party applications.

Building your own flow

1. Create a Linked account on Cobalt when a user signs up for your app

Customers in Cobalt is often termed as Linked account. In order to enable your customer to connect to third party app, you first need to create a linked account for them. We recommend you create a linked account at the same time as your customer signs up within your app.

To create a Linked Account (customer) in Cobalt, you can use the following CURL command or follow the provided guide: 

Replace YOUR_API_KEY with your Cobalt API key and provide the necessary information for the new Linked Account, such as YOUR_CUSTOMER_ID, Customer Name, customer@email.com, and any additional metadata in the JSON payload.

By creating a Linked Account for your customer, you can easily track their connection status and manage their integration with third-party apps seamlessly from the moment they sign up within your app.

Retrieve a list of all integrations available to connect and display them in your UI

With the above call you can get all the details related to an appliction for a user i.e connection status, logo, app description etc.

We recommend using the assets provided by Cobalt as they meet the requirements of the supported integrations. For example QuickBooks Online require the specific use of QuickBooks branded buttons, including specific hover states.

3. Generate session token

With session tokens, Cobalt enables secure and seamless user interactions with the Cobalt frontend SDK, ensuring that each request is authenticated and authorized properly during the user’s session.

The session token gets expired in 24 hours. Please make sure you generate a new token in every new session or within 24 hours.

4. Direct your user to authorize a connection with their selected platform

Cobalt frontend SDK documentation: https://github.com/gocobalt/cobalt-js#cobaltjs

The preferred way to install the Cobalt frontend SDK for javascript is to use the npm package manager. Simply type the following into a terminal window:

npm install @cobaltio/cobalt-js

Alternatively, you can also install the frontend SDK on the browser using the script tag:

<!-- use a specific version -->
<script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3.0.1"></script>

<!-- use a version range instead of a specific version -->
<script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3"></script>
<script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js@3.0"></script>

<!-- omit the version completely to use the latest one -->
<!-- you should NOT use this in production -->
<script src="https://cdn.jsdelivr.net/npm/@cobaltio/cobalt-js"></script>

Initializing the javascript SDK using session token from step 3:

const cobalt = new Cobalt({
    // the token you generate for linked accounts using the cobalt backend SDK
    token: "COBALT_SESSION_TOKEN",
});

5. Manage Connections

Cobalt provides the flexibility for you to manage your customers’ application connections. The .connect() method lets your customers to connect to an application platform, authorizing you to access the platform apis and data on their behalf.

cobalt.connect("slack") // opens a new tab for oauth apps
cobalt.connect("twilio", {
  number: <"Registered number">,
  sid: "ACCOUNT_SID",
}) // saves the auth data for key based apps

Once authenticated, you would be able to manage the config associated with the customer(Linked account).

The .disconnect() method similarly, lets the user to disconnect from the application platform, revoking the authorization and deleting any and all configurations of the Linked account saved for that particular application.

cobalt.disconnect("slack")

6. Allow users to configure the connection

Once the user has successfully authenticated in their platform, he is redirected back to your app integration page. Use the .config() method to find an exisiting config or creating a new config for the linked account.

cobalt.config({
  slug: "slack",
  config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
  labels: {}, // optional dynamic labels
})

7. Save/Update the configuration

The .config() method provides you with all the published workflows and settings input for the user required to execute the orchestration. The user can now enable the workflows, enter data for the settings and map fields. These updates to the config can be made using the .updateConfig() method.

cobalt.updateConfig({
  slug: "slack",
  config_id: "OPTIONAL_ID_FOR_THIS_CONFIG",
  fields: {
    "64da0b57c9ae95561bb0a24d": "C044U7Q074J"
  },
  workflows: [
    {
      id: "64d1fac58716dc5065127ffe",
      enabled: true,
      fields: {
        "64da0b57c9ae95561bb0a24f": "C044U7Q074J"
      }

    }
  ]
})