Intacct provides an SDK for PHP so that you can interact with the Web Services gateway using PHP. You can work with PHP objects to make your requests and parse responses—you no longer need to work directly with the underlying XML API.

This topic provides a high-level overview of the SDK. When you are ready to start coding, try the quick start example and keep the reference documentation handy for delving deeper.

Client model

The SDK uses a client model for sending requests to the gateway. You construct a client that provides Web Services credentials, company credentials, and other optional settings, then use that client to execute your requests.

There are two kinds of clients:

Both clients extend AbstractClient, which provides a common constructor and a method for generating random control IDs for requests.

The constructor accepts an array of parameters that can include login credentials, configuration options, logger choices, the gateway endpoint, and so forth. The following shows a basic IntacctClient constructor that accesses credentials from a file.

<?php
$client = new IntacctClient([
    'profile_file' => __DIR__ . '\.intacct\credentials.ini',
]);

If credentials are not provided to the constructor, the client will default to use environment variables. During instantiation, the default endpoint (https://api.intacct.com/ia/xml/xmlgw.phtml) is used, and the client executes a getAPISession request behind the scenes to get an active session.

Company operations

The underlying XML API functions are made available through classes in Intacct/Functions. The classes that provide object-specific functionality are under feature namespaces, and the classes that provide generic functionality are in a single namespace. For example, object-specific classes such as CustomerCreate, JournalEntryDelete, and ContactUpdate are under their respective categories, and generic classes such as Read, ReadByQuery, and Read are under a single Common namespace.

You should use the object-specific classes for creating, updating, or deleting objects. The generic classes are intended for use in getting information about objects. (The Create, Delete, and Update generic classes are scheduled for deprecation and should not be used.)

All these classes implement FunctionInterface and extend AbstractFunction, which gives them access to an XML writer that translates the PHP objects into XML behind the scenes.

The IntacctClient can execute instances of any of the generic or object-specific classes—the QueryClient is specialized and only supports ReadByQuery.

Usage

The tasks involved in building up and sending a request vary depending on which client you use:

Error handling

There are several categories of errors that can occur when sending requests to the gateway. Your code should handle these.

Possible cause Exception
Invalid Web Services sender ID or password ResponseException
Invalid company user ID or password OperationException
Missing parameter on a function call InvalidArgumentException (PHP exeception)
Invalid query or aborted transaction ResultException

Refer to the error handling example for usage information.

Note that helper functions are available for checking the status of results:

Credentials

There are several approaches for supplying Web Services and company credentials to the PHP SDK, described below.

Important: Always safely secure your credentials.

User-defined environment variables

You can define variables in a login.cfg file and use parse_ini_file() to load them. See the quick start example.

Default environment variables

You can define environment variables in your operating system. The PHP SDK will look for these environment variables if you did not supply credentials when constructing the client.

Credentials file

You can provide credentials in a credentials.ini file at ~/.intacct/credentials.ini. This file uses PHP-style variable names:

The default profile is declared as [default], and you can set up additional profiles for different companies. The following example shows a credentials file with a default profile and two company profiles.

[default]
sender_id = "myWebSenderId"
sender_password = "****"
user_id = "myUserId"
user_password = "***"
company_id = "myCompanyId"

[acme-co]
sender_id = "myWebSenderId"
sender_password = "****"
user_id = "acmeUserId"
user_password = "***"
company_id = "acmeCoId"

[gadget-co]
sender_id = "myWebSenderId"
sender_password = "****"
user_id = "gadgetCoUserId"
user_password = "***"
company_id = "gadgetCoId"

The use of different profiles is illustrated in the error handling example.

What’s Next?

Provide feedback