Getting Started
This tutorial will get you up and running quickly with the Sage Intacct SDK for PHP.
Make sure you meet the system requirements before continuing.
Set up
-
Download or clone the Sage Intacct SDK for PHP examples.
-
Create a new PHP project for the examples in your IDE of choice (PHPStorm, NetBeans, etc.).
-
Note that the
composer.json
file in the project root specifies the Sage Intacct SDK for PHP (intacct/intacct-sdk-php
) as a dependency. -
Open a terminal window in the root folder and run
composer install
.This creates a
vendor
folder and adds the Sage Intacct SDK for PHP libraries and dependencies. -
Create a
.credentials.ini
file in the root folder and provide your developer/sandbox credentials as follows:[default] sender_id = "mysenderid" sender_password = "mysenderpassword" company_id = "mycompanyid" user_id = "myuserid" user_password = "myuserpassword"
The
default
profile is automatically used unless overridden in theClientConfig
or by environment variables.Note: The credentials file is excluded from source control via the
.gitignore
file. You should take precautions to secure this file.
Understand the code
-
Take a look at
bootstrap.php
in the project root and note that it:-
Includes the Composer autoloader:
$loader = require __DIR__ . '\vendor\autoload.php';
-
Sets up a Monolog HTML logger.
$logger = new \Monolog\Logger('intacct-sdk-php-examples');
-
Creates a client config that relies on your credentials file:
$clientConfig = new ClientConfig(); $clientConfig->setProfileFile(__DIR__ . '/.credentials.ini');
-
Creates an online client that uses the client config:
$client = new OnlineClient($clientConfig);
-
-
Open
getting-started.php
and note that it:-
Requires
bootstrap.php
:require __DIR__ . '/bootstrap.php';
-
Constructs a
Read
object to get information about a customer with the record number 33:$read = new Read(); $read->setObjectName('CUSTOMER'); $read->setFields([ 'CUSTOMERID', 'NAME', 'RECORDNO', 'STATUS', ]); $read->setKeys([ 33 ]);
-
Executes the query using the online client instance (
$client
) that was instantiated in the bootstrap file:$response = $client->execute($read); $result = $response->getResult();
-
Run the example
-
Run the
getting-started.php
file:php getting-started.php
-
Observe the terminal output, for example:
Result: [{"CUSTOMERID":"C-9829","NAME":"Jenifer Jones","RECORDNO":"33","STATUS":"active"}]
-
If you don’t get a result, replace the example record number with one or more that can be found in your company, for example:
$read->setKeys([ 12, 10, 44 ]);
-
Open the generated
logs/intacct.html
file in your browser and review the entries.The SDK provided one debug entry for the HTTP request with the Sage Intacct endpoint (/ia/xml/xmlgw.phtml HTTP/1.1), and another for the single response. The response includes the request control ID, which defaults to the timestamp of the request, and the function control ID, which defaults to a random UUID.
Extra credit
Log level and format
-
Add the following lines to the bottom of the bootstrap file to change the SDK’s log message format and log level:
$formatter = new \Intacct\Logging\MessageFormatter( '"{method} {target} HTTP/{version}" {code}' ); $client->getConfig()->setLogLevel(\Psr\Log\LogLevel::INFO); $client->getConfig()->setLogMessageFormatter($formatter);
-
Run the PHP file again, then open
logs/intacct.html
and review the new entries at the bottom. Note the response code is listed after the HTTP method in the second INFO block."POST /ia/xml/xmlgw.phtml HTTP/1.1" 200
What’s next?
-
Read the SDK overview for high level information.
-
Try an example that lists AR invoices based on attributes of associated customers.
-
Browse the reference documentation for the SDK.