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 as a dependency:

    "intacct/intacct-sdk-php": "2.*"
    
  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.

    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 ReadByQuery instance that queries for vendors:

      $query = new ReadByQuery();
      $query->setObjectName('VENDOR');
      $query->setPageSize(1); // Keep the count to just 1 for the example
      $query->setFields([
         'RECORDNO',
         'VENDORID',
         'NAME',
      ]);
      
    • Executes the query using the online client instance ($client) that was instantiated in the bootstrap file:

      $response = $client->execute($query);
      $result = $response->getResult();
      ...
      echo "Success! Number of vendor objects found: " . $result->getTotalCount() . PHP_EOL;
      

Run the example

  1. Run the getting-started.php file:

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

    Success! Number of vendor objects found: 14
       
    Process finished with exit code 0
    
  3. 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.


What’s next?

Provide feedback