Training Day
Simple Ledger Scripts

Send QBO HTTP Request

A specialized script for interacting with the QuickBooks Online API from FileMaker, handling authentication, token management, and error handling.

Introduction

The "Send QBO HTTP Request" script provides a specialized interface for interacting with the QuickBooks Online (QBO) API from FileMaker. This script handles the complexities of QBO authentication, token management, request formatting, and error handling to simplify integration with QuickBooks Online services.

Unlike direct HTTP requests, QBO API calls require OAuth token management, including automatic token refresh when access tokens expire. This script encapsulates that logic while providing a clean interface for making various QBO API calls.

Key Features

  • Automatic Token Management: Detects expired access tokens and refreshes them automatically
  • Standardized Error Handling: Converts QBO API errors into consistent FileMaker error formats
  • Retry Logic: Automatically retries requests after token refresh when needed
  • Optional Debug Logging: Logs requests and responses when debugging is enabled

Usage

To use this script, call it using the FileMaker "Perform Script" step:

Perform Script [ "Send QBO HTTP Request" ; JSONObject ]

Script Parameter

The script accepts a single JSON object parameter with the following properties:

PropertyTypeDescription
pathstringThe endpoint path for the API call (required)
queryobject(Optional) Name-value pairs that serialize to what comes after the "?" in the URL
datastring/object(Optional) Data to send with POST, PUT, PATCH requests

Return Value

On success, the script returns the body of the QBO API response as a JSON object.

Error Handling

If an error occurs, the script returns an error object with the following structure:

PropertyTypeDescription
codenumberError code
messagestringA description of the error
qboFaultobject(Optional) Detailed error from QBO if available

Common error codes:

  • -100: QBO API Bad Request
  • -101: Unauthorized
  • -102: QBO Internal Server Error
  • -103: QBO API Service Unavailable

Implementation Details

The script follows this process flow:

  1. Request Validation: Verifies that required parameters are present
  2. Token Management: Checks if the access token is expired and refreshes if needed
  3. Request Construction: Builds the complete request URL and adds authorization headers
  4. API Call: Makes the HTTP request to the QBO API
  5. Token Refresh & Retry: If a 401 error is received, refreshes the token and retries
  6. Response Handling: Processes the response, handling errors consistently
  7. Debug Logging: Logs the request and response if debugging is enabled

Dependencies

This script depends on:

  • The "Refresh Access Token" script for token renewal
  • The "HTTP ( request )" script for making HTTP requests
  • The "QBO Logger" script for debug logging
  • A "QBOSettings" table to store token information

Debug Mode

Set the $$DEBUG variable to enable detailed request/response logging to the "QBO.log" file.

On this page