This tutorial will get you up and running quickly with the Sage Intacct SDK for .NET. Make sure you meet the system requirements before continuing.


Set up

  1. Download and install .NET Core 2.0 SDK, if you do not already have it installed.

  2. Download or clone the Sage Intacct SDK for .NET examples.

  3. Open the intacct-sdk-net-examples.sln solution file in your IDE of choice (Rider, Visual Studio 2017, etc). This will display one project, Intacct.Examples which is a .NET Core console application.

  4. Open the Intacct.Examples folder and note that the Intacct.Examples.csproj file specifies the Sage Intacct SDK for .NET as a dependency:

    <PackageReference Include="Intacct.SDK" Version="2.0.0" />
    
  5. Open a terminal window in the root folder and run nuget restore, if your IDE has not already done this on project load.

    This downloads the Sage Intacct SDK for .NET libraries and dependencies.

  6. Create a credentials.ini file in the Intacct.Examples project 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.cs in the project root and note that it:

    • Has a static Logger() function for setting up an NLog logger:

      public static ILogger Logger()
      {
          FileTarget target = new FileTarget
          {
              FileName = "${basedir}/logs/intacct.log"
          };
          SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);
          ILogger logger = LogManager.GetLogger("intacct-sdk-net-examples");
               
          return logger;
      }
      
    • Has a static Client() function for setting up a client config that relies on your credentials file and returns a new online client that uses the client config:

      public static OnlineClient Client(ILogger logger)
      {
          ClientConfig clientConfig = new ClientConfig()
          {
              ProfileFile = Path.Combine(Directory.GetCurrentDirectory(), "credentials.ini"),
              Logger = logger,
          };
          OnlineClient client = new OnlineClient(clientConfig);
               
          return client;
      }
      
  2. Open Program.cs and note that it is the Main() function for your console application. This effectively prompts you for an example option to run. It also wraps repetitive code to help avoid one project per example provided.

  3. Open GettingStarted.cs and note that it:

    • Constructs a ReadByQuery instance that queries for vendors:

      ReadByQuery query = new ReadByQuery()
      {
          ObjectName = "VENDOR",
          PageSize = 1, // Keep the count to just 1 for the example
          Fields =
          {
              "RECORDNO",
              "VENDORID",
              "NAME"
          }
      };
      
    • Executes the query using the online client instance (client) that was instantiated in the bootstrap file:

      Task<OnlineResponse> task = client.Execute(query);
      task.Wait();
      OnlineResponse response = task.Result;
      Result result = response.Results[0];
      ...
      Console.WriteLine("Success! Number of vendor objects found: " + result.TotalCount);
      

Run the example

  1. Run the project, and when prompted, enter 1 and press enter:

    "C:\Program Files\dotnet\dotnet.exe" Intacct.Examples/bin/Debug/netcoreapp2.0/Intacct.Examples.dll
       
    Pick an option to run:
     1 - Getting started
     2 - List vendors
     3 - CRUD customer
     4 - Custom object function
    
  2. Observe the terminal output, for example:

    Success! Number of vendor objects found: 14
    
  3. Open the generated Intacct.Examples/bin/Debug/netcoreapp2.0/logs/intacct.log file in a text editor 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. Edit the public static Client function in the Bootstrap class to change the SDK’s log message format and log level. This is done by adding LogLevel and LogMessageFormatter property setters:

    public static OnlineClient Client(ILogger logger)
    {
        ClientConfig clientConfig = new ClientConfig()
        {
            ProfileFile = Path.Combine(Directory.GetCurrentDirectory(), "credentials.ini"),
            Logger = logger,
            LogLevel = LogLevel.Info,
            LogMessageFormatter = new MessageFormatter("\"{method} {target} HTTP/{version}\" {code}"),
        };
        OnlineClient client = new OnlineClient(clientConfig);
           
        return client;
    }
    
  2. Run the project again, then open logs/intacct.log 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