This is a sample Rails application that demonstrates how to integrate with QuickBooks APIs using OAuth 2.0 authentication and use custom fields.
- OAuth 2.0 authentication with QuickBooks
- Custom Fields API integration via GraphQL
- Ruby 3.4.7 or higher
- Rails 7.2.0 or higher
- QuickBooks Developer Account
- QuickBooks Online Account
- ngrok (for local development)
The API requires the following OAuth scopes for full functionality:
com.intuit.quickbooks.accounting- Access to QuickBooks accounting dataapp-foundations.custom-field-definitions- Required for Custom Fields API accessapp-foundations.custom-field-definitions.read- Required for Custom Fields API access
Please note that the company you test this app with needs to have some customers and products so that an invoice with the defined custom field can be created.
- Create an account at this link: https://dashboard.ngrok.com/get-started/setup/macos
- Run this command in the terminal :
brew install ngrok - Run the following command to add your authtoken to the default
ngrok.yml configuration filethen run ngrok config add-authtoken <TOKEN-VALUE>- In the terminal run:
ngrok http 3000for this project or replace the 3000 with the port number of your choosing - You should now see a url in the Forwarding section in the terminal that starts with https and forwards to a local host adddress (https://234562f900c4.ngrok-free.app -> http://localhost:3000 ).
- Copy that url and paste in the QB_REDIRECT_URI in your .env file with /callback at the end as well as in your App's production redirect urls section
-
Clone the repository:
git clone <repository-url> cd SampleApp-CustomFields-Ruby
-
Configure your QuickBooks app:
- Go to Intuit Developer Portal
- Create a new app or use an existing one
- Enable Custom Fields and Accounting API scopes
- Add your redirect URI (e.g.,
https://your-ngrok-url/callback)
-
Update configuration:
- Open
config/quickbooks.yml - Update the OAuth2 provider details with your app credentials:
oauth: client_id: YOUR_CLIENT_ID client_secret: YOUR_CLIENT_SECRET redirect_uri: YOUR_REDIRECT_URI
- Or, set them in environment variables:
QB_CLIENT_ID,QB_CLIENT_SECRET,QB_REDIRECT_URI
- Open
-
Start ngrok:
ngrok http 3000
-
Run the application in a separate terminal window:
bundle exec rails server
- Visit
http://localhost:3000in your browser - Step 1: Connect to QuickBooks - Click "Connect to QuickBooks" to authenticate
- Step 2: Enter Custom Field Name - Enter the name of the custom field click "Create Custom Field" to generate the new definition
- Step 3: Enter Info for a new Invoice - Select Customer, Item, Custom Field Value and enter an amount.
- Step 4: Create Invoice - Click "Create Invoice" to create the specified invoice for your company.
/- Home page with multi-step workflow/qbo-login- Initiates OAuth flow/callback- OAuth callback handler/create_custom_field- Creates a custom field in QuickBooks/create_invoice- Creates an invoice in QuickBooks/logout- Logs out of QuickBooks
The application includes error handling for:
- OAuth authentication failures
- API request failures
- Missing parameters
- Invalid scopes
-
"Forbidden" Error
- Ensure
app-foundations.custom-field-definitionsandapp-foundations.custom-field-definitions.readscopes are included in OAuth authorization - Check that all required scopes are configured in
quickbooks.yml
- Ensure
-
"Invalid URI or environment" Error
- Verify
Environmentis set to"production" - Check that
RedirectUrimatches your QuickBooks app configuration
- Verify
-
GraphQL Query Errors
- Mutation uses
AppFoundationsCreateCustomFieldDefinition - In the variables file, "associatedEntity" should be set to "SALE_INVOICE"
- Mutation uses
-
Nothing happens after creating a custom field
- Make sure you have customers and items in your company
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
For support, please visit the Intuit Developer Community or create an issue in this repository.