This example sets up five different error scenarios that show you how to catch exceptions. As you work through the example you will:

Prerequisites

Example 1: Invalid Web Services sender ID

  1. Open the .intacct/credentials.ini file and update only the wrong_sender_id profile—you can provide correct information for the other variables.

    [wrong_sender_id]
    sender_id = "wrongSenderId"   <--- Provide incorrect entry
    sender_password = "****" 
    user_id = "myUserId"
    user_password = "****"
    company_id = "myCompanyId"
    
  2. In ErrorHandlingExample.php, note the code that creates a IntacctClient instance using the profile you set up:

    <?php
    try {
       $client = new IntacctClient([
           'profile_name' => 'wrong_sender_password',
          'profile_file' => __DIR__ . '\.intacct\credentials.ini',
    ]);
    
  3. Further down, note how the ResponseException is caught and printed.

    <?php
    } catch (ResponseException $e) {
       echo "Example 1, " . $e->getMessage(). "\n";
        foreach ($e->getErrors() as $error) {
            echo $error . "\n"; 
        };
        echo "\n"; 
    }
    
  4. Run the example to see the error response:

    Example 1, Response control status failure
    XL03000006 Incorrect Intacct XML Partner ID or password.
    

Example 2: Invalid company user ID

  1. Open the .intacct/credentials.ini file and update only the wrong_user_id profile—you can provide correct information for the other variables.

    [wrong_user_id]
    sender_id = "myWebSenderId"
    sender_password = "****"
    user_id = "wrongUserId"   <--- Provide incorrect entry
    user_password = "****"
    company_id = "myCompanyId"
    
  2. Comment out the try/catch for example 1, and uncomment the try/catch for example 2.

  3. Note how the OperationException is caught and printed.

  4. Run the example to see the error response:

    Example 2, Response authentication status failure
    XL03000006 Sign-in information is incorrect
    

More examples

Examples 3 through 5 demonstrate errors that pertain to the content of the requests. Feel free to uncomment and run these examples.

Note: These examples require a default profile in intacct-sdk-php-examples/.intacct/credentials.ini.

Example Error condition Message
3 InvalidArgumentException: Missing parameter for object creation Example 3, Customer Name is required for create
4 ResultException: Empty query results Example 4, An error occurred trying to get query records. Query Failed Object Definition APBIL not found
5 ResultException: Incorrect object name causing transaction rollback Example 5, Result status: aborted. XXX Object definition GLENTRIES not found. XL03000009 The entire transaction in this operation has been rolled back due to an error.

The fixes

In case you are curious, you can fix the above errors as follows:

Provide feedback