You are currently viewing Integrating Salesforce with QuickBooks using Salesforce Flows

Integrating Salesforce with QuickBooks using Salesforce Flows

Objective:

This article will provide a detailed, step-by-step guide on how to post data from Salesforce to QuickBooks using Salesforce Flows. We will be walking you through the specific use case of creating a Contact in Salesforce, resulting in the creation of a corresponding Customer entry in QuickBooks. 

Approach:

An after-record-triggered flow on Contact initiates an HTTP POST Callout to QuickBooks. A Named Credential is created to specify the URL of a callout endpoint and its required authentication parameters. The record-triggered flow utilizes the Named Credential to initiate the callout. The same methodology can be used in Screen Flows and to integrate other QuickBooks entities.

Authentication

Setting up QuickBooks OAuth 2.0:

  1. Go to Intuit’s Developer website: Sign in using your QuickBooks credentials.
  2. Access your app: Navigate to the dashboard and select your specific app.
  1. Get authentication details: Click on “Keys and Credentials” to find your Client ID and Client Secret.

Creating an authorization provider in Salesforce:

  1. Log in to your Salesforce account: Use the search bar to find “auth. Provider.”
  2. Create a new provider: Select “New” and choose “OpenIDConnect” as the provider type.

3. Fill in the required details: Enter the information obtained from QuickBooks, such as Client ID and Client Secret, in the fields provided
Authorize Endpoint URL: https://appcenter.intuit.com/connect/oauth2
Token Endpoint URL:https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer

By following these steps, you’ll establish the connection between QuickBooks and Salesforce through OAuth 2.0, enabling seamless integration and authentication between the two platforms.

Configuring Redirect URIs in QuickBooks:

Add Redirect URIs:

  1. Copy the callback URL from the Auth Provider setup in Salesforce.

2.   Visit QuickBooks ‘Keys & OAuth’ 

3.   Paste the copied callback URL into the specified field for ‘Redirect URIs.’

By performing these, you’ll ensure that the respective callback URLs are correctly integrated into QuickBooks, allowing seamless authentication between Salesforce and QuickBooks in both settings.

Creating External Credentials:

  1. Go to Setup: Use the search bar in Salesforce and look for “Named Credentials.”
  2. Navigate to External Credentials: Click on the ‘External Credentials’ tab and select ‘New.’
    • Label and Name: Provide a label and name for the external credentials.
    • Authentication Protocol and Flow Type: Choose OAuth 2.0 as the Authentication Protocol and Browser Flow as the Authentication Flow Type
    • Enter Scope: Set the scope as ‘com.intuit.quickbooks.accounting’ 
    • Select Authentication Provider: From the available options, choose the recently created Auth Provider that you’ve set up. 

3. Create External Principals:

  • Click on the “New” button in the principal section of external credentials.
  • Enter the required data as shown in the provided screenshot or instructions. The Parameter name can be of your choosing.

Creating Permission Set for External Callouts:

  • Go to Setup and Search for Permission Sets:
  • Click on “New” to create a new permission set.
  • Add a name and label.

Select “External Credential Principal Access.” from the list.     

  • Editing Permission Set:Click on the edit button.
  • From the available list, select the external credentials and principals created earlier.-> Save the changes.
  • Manage Assignment: Click on “Manage Assignments.”
  • Choose “Add Assignment” to assign this permission set.-> Choose the user intended for this permission set. -> click on next -> Click on Assign -> Click on the Done button
  • For demonstration purposes, I utilized the System Admin user to assign the permission set
  • Assign the permission set to the users creating the Contact. This step is vital since the record-triggered flows run in the context of the user performing the DML. 

Once you’ve set up the permission set, you can authenticate the QBPrincipal by following these steps:

  1. Go back to external credentials
  2. Navigate to the principal and click on “Actions.”
  1. Select “Authenticate.” This action will redirect you to the QB login page.
  2. Log in using your credentials on the QB login page.
  3. After successful login, you’ll notice that the Authentication Status reflects “configured,” indicating the authentication process is completed.

Creating Named Credentials for QuickBooks Integration:

  • Go to Setup and Search for Named Credentials:
  • Click on “New” to create a new named credential.
  • Enter Details: Fill in the necessary details.
  • For creating a customer in QuickBooks, use this API endpoint: https://sandbox-quickbooks.api.intuit.com/v3/company/4620816365363127090/customer?minorversion=69
    Please Note: The endpoint URL will differ for a production QuickBooks instance.
  • Add External Credentials: Include the external credentials you previously created within the named credential.

After creating the Named Credentials, proceed by scrolling down and adding the “Accept” type as “application/json” in the custom header settings.

Setting up a Record-Triggered Flow with Asynchronous Path and HTTP Callouts

Create a New Flow:

  • Navigate to Setup and search for “Flows”.
  • Click on “Create New Flow” and choose “Record-Triggered Flow”.

Configure Flow Settings:

  • Select the object as “Contact”.
  • Set the event to “Record Created”.
  • When an external web request is used in a record-triggered flow, using an asynchronous method is crucial. Without it, there’s a risk of flow interruptions or system timeouts, as it waits for external responses, impacting overall performance.   
  • Add Asynchronous Path:
    • Check the option: “Include a Run Asynchronously path to access an external system after the original transaction for the triggering record is successfully committed”.
    • This step is automatically included by checking the asynchronous path option in the flow settings.

Configure HTTP Callouts:

  • Click on the plus sign and select the action.
  • Choose “Create HTTP Callouts”.
  • Enter a name for the new http callout.
  • Select the required Named Credentials from the list and click “Next”.

Configure Invocable Action:

In the “Configure Invocable Action”:

  • Provide the label name.
  • Select the method as “POST”.
  • Scroll down to “Provide Sample Request”, Click on the New and Please add the input in the sample request in JSON format. 
  • For reference and guidelines on the sample request structure, kindly check the provided link – Intuit Developer API – Create a Customer.
  • Add the request, then review your JSON by clicking ‘Review’ at the bottom, and finally, click ‘Done’ to confirm.
  • Likewise, just as we structured the request for the HTTP callout, we format the response in JSON from the HTTP callout
  • Ensure that you’ve added ‘application/json’ in your Named Credentials under custom headers.
  • Click on “Save”.
  • Upon saving, an external service for your HTTP callout will be generated automatically

Configuring HTTP Callout: Final Steps

  • After adding your sample request and sample response and saving it, the new action screen will appear. Then, proceed to add the label and API name
  • Scroll down to the ‘Set Request Body’ section.
  • Go to the ‘Value’ field and click on ‘New Resource’.
  • This action will automatically generate the Apex-defined class.
  • Provide the API name for the class and click ‘Done’.
  • Your HTTP callout configuration is now completed. Click ‘Done’ to finalize the setup.

Assign the Variables

In the process of utilizing an external service, an Apex class was generated by Salesforce. Assign the record variables of contact to the generated Apex Class  variables.

  • Add the assignment before the callout.

  • Provide a suitable label and name.
  • Set Variable Value: Set the variable value by adding the variable from the Apex-defined class and assign the value from your record.
  • Finalize and Save the Flow: Once all configurations are completed, Give proper label, api name, description and  save the Flow.

Outcome of the Integration

Conclusion

Salesforce record triggered flows are customized to integrate Salesforce with QuickBooks. Although the article illustrates the QuickBooks API, the same methodology can be applied to integrate with other external systems providing APIs. 

Looking for QuickBooks and Salesforce integration help? Reach out to us at [email protected]