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

  1. Download or clone the Sage Intacct SDK for PHP examples.

  2. Create a new PHP project for the examples in your IDE of choice (PHPStorm, NetBeans, etc.).

  3. Note that the composer.json file in the project root specifies the Sage Intacct SDK for PHP (intacct/intacct-sdk-php) as a dependency.

  4. 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.

  5. 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 the ClientConfig 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

  1. 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);
      
  2. 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

  1. Run the getting-started.php file:

    php getting-started.php
    
  2. Observe the terminal output, for example:

    Result:
    [{"CUSTOMERID":"C-9829","NAME":"Jenifer Jones","RECORDNO":"33","STATUS":"active"}]
    
  3. 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
     ]);
    
  4. 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

  1. 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);
    
  2. 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?

Provide feedback