The authentication flow in Conductor is a user interface walkthrough that allows your users to securely connect their QuickBooks Desktop installation to their Conductor account. For an example, check out this demo of the auth flow.

There are two main approaches to integrating the auth flow with your application:

  1. Integrate the auth flow with your backend to manage multiple users and connections.
  2. Generate shareable auth links for getting started quickly or one-off connections.

Integrate the auth flow with your backend

If you are building a multi-user service where each user needs to connect their QuickBooks Desktop account to your application, you’ll want to integrate Conductor’s QuickBooks Desktop auth flow into your backend.

1

Create an end-user

Consider you have an end-user of your application who needs to connect their QuickBooks Desktop to your application. Begin by creating an end-user for that user and saving their id to your database. You will use this id to match your users to their corresponding QuickBooks Desktop connection in Conductor.

If your database has a users table, consider creating a column called conductor_end_user_id.

Create an end-user
import Conductor from "conductor-node";
const conductor = new Conductor("{{YOUR_SECRET_KEY}}");

// Replace the placeholders with your actual data.
const endUser = await conductor.endUsers.create({
  companyName: "{{END_USER_COMPANY_NAME}}",
  sourceId: "{{UNIQUE_ID_FROM_YOUR_DB}}",
  email: "{{END_USER_EMAIL}}",
});

// Save the end-user ID to your database.
await db.users.update({
  conductorEndUserId: endUser.id,
});
2

Check if the end-user has an active QuickBooks Desktop connection

The next step is to initiate an auth session for your user to connect their QuickBooks Desktop. However, what if they already has an active connection? Or, what if they previously started the auth flow but didn’t complete it?

You must send any request and check the error.code to determine the appropriate action. The key distinction in error handling is:

  • INTEGRATION_CONNECTION_NOT_SET_UP: The user needs to complete the auth flow.
  • Other connection errors: The user needs to take a specific action (like restarting QuickBooks) but does not need the auth flow.

Imagine your application has a web app where your users configure the integrations with their application. If you create a section for the QuickBooks Desktop integration, you can use the following approach to track whether an active connection already exists:

Check the connection status
try {
  // Ping to check the connection status.
  await conductor.endUsers.ping("{{END_USER_ID}}", "quickbooks_desktop");
  updateUI("QuickBooks Desktop is successfully connected!");
} catch (error) {
  if (error instanceof ConductorIntegrationConnectionError) {
    if (error.code === "INTEGRATION_CONNECTION_NOT_SET_UP") {
      // This specific error code indicates the user needs to go through the auth
      // flow. Either they never started it, or didn't complete it.
      const authSession = await conductor.authSessions.create({
        publishableKey: "{{YOUR_PUBLISHABLE_KEY}}",
        endUserId: "{{END_USER_ID}}",
      });
      updateUI("Set up your QuickBooks Desktop connection: " + authSession.authFlowUrl);
    } else {
      // Display connection errors for your user to resolve.
      updateUI("An error occurred: " + error.userFacingMessage);
    }
  } else {
    throw error;
  }
}

Note: Replace updateUI() with your actual code that updates your application’s UI based on the status or errors received.

For a quick start, particularly useful for pilot deployments or small-scale operations, generate a secure, shareable link for the QuickBooks Desktop auth flow:

1

Create an end-user

If you haven’t already done so, create an end-user and save their id. You will use this id to authenticate future requests.

import Conductor from "conductor-node";
const conductor = new Conductor("{{YOUR_SECRET_KEY}}");

// Replace these placeholders with your own values.
const endUser = await conductor.endUsers.create({
  companyName: "{{END_USER_COMPANY_NAME}}",
  sourceId: "{{UNIQUE_ID_FROM_YOUR_DB}}",
  email: "{{END_USER_EMAIL}}",
});
console.log("Save this end-user ID to auth future requests:", endUser.id);
2

Create an auth session

Using the end-user’s ID, create an auth session with an extended link expiry time if needed:

import Conductor from "conductor-node";
const conductor = new Conductor("{{YOUR_SECRET_KEY}}");

const authSession = await conductor.authSessions.create({
  publishableKey: "{{YOUR_PUBLISHABLE_KEY}}",
  endUserId: "{{END_USER_ID}}",
  linkExpiryMins: 60 * 24, // 24 hours
});
console.log("Send this link to your customer to complete the auth flow:", authSession.authFlowUrl);
3

Share the auth flow link

Share the generated authFlowUrl with your end-user to direct them to the auth flow to connect their QuickBooks Desktop instance to your application.

The link will resemble this mock example:

https://connect.conductor.is/qbd/auth_sess_client_secret_1234567abcdefg?key={{YOUR_PUBLISHABLE_KEY}}