This example shows you how to:


Set up credentials

A template credentials file is provided in the examples directory.

  1. Open the credentials.ini file and update only the default profile with your information.

    sender_id = "myWebSenderId"
    sender_password = "****"
    user_id = "myUserId"
    user_password = "****"
    company_id = "myCompanyId"

    The other two profiles are for a different example and can be left alone for now.

  2. Create a directory called .intacct in your project and copy the modified file into this directory:


Learn about the code

  1. Open QueryClientExample.php and note the code that constructs a QueryClient that loads the credentials.

    $queryClient = new QueryClient([
        'profile_file' => __DIR__ . '\.intacct\credentials.ini',
  2. Look at how a ReadByQuery object is constructed, initialized, and executed to perform a query on APBILL objects.

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

Run the program

  1. Run the program from your IDE and examine the results.

    You get a listing of the number of APBILL objects in your company. You also get a listing with the creation date, amount posted, and the name for each APBILL.

    Number of APBILL objects: 904
    Record Created: 07/15/2008
    Amount posted: 3825.9 USD
    Record Created: 07/15/2008
    Amount posted: 2550.6 USD
    Record Created: 06/15/2008
    Amount posted: 20468.84 USD
  2. Look at the code that printed your results to see how the field values are printed out.

    echo "Number of APBILL objects: " . $records->count() . "\n\n";  
    foreach ($records as $record) {
        echo "Record Created: " . $record['WHENCREATED'] . "\n";   
        echo "Amount posted: " . $record['TOTALENTERED'] . " " . $record['CURRENCY'] . "\n"; 
        echo "Name: " . $record['VENDORNAME'] . "\n\n";                                      
  3. Using the API documentation for APBILL as a guide, modify the foreach loop to print information for different fields.

    Note that a field with no value is converted to an empty array in the query results, which will result in an “Array to string conversion” error in your output.

  4. Try a query for a different object.

    For example, the following query returns General Ledger accounts that were created before 1/1/2008.

    $readByQuery = new ReadByQuery();             
    $readByQuery->setQuery("WHENCREATED < '1/1/2008'"); 
    $records = $queryClient->executeQuery($readByQuery); 

    Note: Don’t forget to modify the foreach loop to return the information you want!

What’s next?

Provide feedback