You use a QueryClient to send a single query and return all matching results. You create and send a query as follows:

  1. Construct a QueryClient instance.

  2. Create a ReadByQuery instance that encompasses the query to perform.

  3. Pass the ReadByQuery instance into the executeQuery method of your QueryClient to send the request.

    All records that match the query are returned.

  4. Parse the response from the executeQuery method.

Construct a QueryClient

The QueryClient constructor can provide login credentials, configuration options, logger choices, and so forth. The following shows a basic constructor that accesses credentials from a separate file.

$client = new QueryClient([
    'profile_file' => __DIR__ . '\.intacct\credentials.ini',

See About the SDK for more information about providing credentials.

Create the query

To create a query, construct a ReadByQuery instance and use setters to build up the query. For example, the following constructs a ReadByQuery instance and configures it to query for APBILL objects with totals greater than 100.

$readByQuery = new ReadByQuery();             
$readByQuery->setQuery("TOTALENTERED > 100"); 

More examples of queries are available in the Web Services Guide.

Execute the query

You call executeQuery on your client and pass in your ReadByQuery instance to send your request to the gateway:

$records = $queryClient->executeQuery($readByQuery); 

All matching records are returned. If you want to prevent a response with a large number of entries, you can use setMaxTotalCount for this. For example, the following throws an exception if there are more than 100 results.

$records = $queryClient->executeQuery($readByQuery, 100);

Tip: If you specifically want to return a given number of results, use the setPageSize function on a ReadByQuery instance and then use IntacctClient to send the query.

Handle the response

An executeQuery call returns an ArrayIterator instance you can cycle through:

foreach ($records as $record) {                                                          
   echo "Record Created: " . $record['WHENCREATED'] . "\n";                             
   echo "Amount posted: " . $record['TOTALENTERED'] . " " . $record['CURRENCY'] . "\n"; 
   echo "Name: " . $record['VENDORNAME'] . "\n\n";                                      

Error Handling

See Error Handling for information about general errors that must be handled for both IntacctClient and QueryClient requests.

What’s Next?

Provide feedback