Using the Sage 100 API to Get Items in PHP

by Endgrate Team 2024-06-29 5 min read

Sage 100 homepage

Introduction to Sage 100 API

Sage 100 is a comprehensive ERP solution designed to streamline business operations for small to medium-sized enterprises. It offers robust features for accounting, inventory management, and customer relationship management, making it a popular choice for businesses looking to enhance their operational efficiency.

Integrating with the Sage 100 API allows developers to access and manipulate data within the Sage 100 system programmatically. This can be particularly useful for automating tasks such as retrieving item information, which can help in maintaining up-to-date inventory records or generating detailed reports.

For example, a developer might use the Sage 100 API to extract item details and integrate them into a custom reporting tool, providing real-time insights into inventory levels and product performance.

Setting Up a Sage 100 Test Environment

Before you can start interacting with the Sage 100 API, it's essential to set up a test environment. This involves configuring the Sage 100 ODBC driver and creating a Data Source Name (DSN) to connect to the Sage 100 ERP system. This setup allows you to safely test API interactions without affecting live data.

Installing and Configuring the Sage 100 ODBC Driver

To begin, ensure that the Sage 100 ODBC driver is installed on your system. Follow these steps to configure it:

  • Access the ODBC Data Source Administrator on your system.
  • Create a new DSN that connects to the Sage 100 ERP system. Ensure you use the correct server, database, and authentication settings.
  • Refer to the official Sage 100 documentation for detailed instructions on configuring the ODBC driver.

Creating a DSN for Sage 100

Once the ODBC driver is installed, follow these steps to create a DSN:

  • Open the ODBC Data Source Administrator.
  • Navigate to the User DSN or System DSN tab and click on "Add."
  • Select the Sage 100 ODBC driver from the list and click "Finish."
  • Enter the necessary connection details, including the server name and database credentials.
  • Test the connection to ensure it is successful.

Configuring Sage 100 for API Access

After setting up the DSN, configure Sage 100 to allow API access:

  • In Sage 100, navigate to Library Master > Setup > System Configuration.
  • On the ODBC Driver tab, enable the C/S ODBC Driver.
  • Enter the server name or IP address where the ODBC application or service is running.
  • Ensure the correct port is set, or leave it blank to use the default port, 20222.

By following these steps, you will have a fully configured test environment to safely interact with the Sage 100 API using PHP.

Sage 100 authentication documentation page.
sbb-itb-96038d7

Making API Calls to Retrieve Items from Sage 100 Using PHP

To interact with the Sage 100 API and retrieve item data, you'll need to use PHP to establish a connection and execute the necessary queries. This section will guide you through the process of setting up your PHP environment, writing the code to make API calls, and handling the responses effectively.

Setting Up Your PHP Environment for Sage 100 API

Before making API calls, ensure your PHP environment is properly configured. You'll need the following:

  • PHP 7.4 or later installed on your system.
  • The ODBC extension enabled in your PHP configuration.
  • Access to the Sage 100 ODBC DSN you configured earlier.

To enable the ODBC extension, locate your php.ini file and ensure the following line is uncommented:

extension=odbc

Writing PHP Code to Connect and Query Sage 100 API

With your environment set up, you can now write PHP code to connect to the Sage 100 API and retrieve item data. Here's a step-by-step guide:


<?php
// Define the DSN and credentials
$dsn = 'SOTAMAS90'; // Replace with your DSN name
$user = 'your_username'; // Replace with your Sage 100 username
$password = 'your_password'; // Replace with your Sage 100 password

// Establish a connection to the Sage 100 database
$conn = odbc_connect($dsn, $user, $password);

if (!$conn) {
    die('Connection failed: ' . odbc_errormsg());
}

// Define the SQL query to retrieve items
$sql = "SELECT ItemCode, ItemDescription, QuantityOnHand FROM CI_Item";

// Execute the query
$result = odbc_exec($conn, $sql);

if (!$result) {
    die('Query failed: ' . odbc_errormsg());
}

// Fetch and display the results
while ($row = odbc_fetch_array($result)) {
    echo "Item Code: " . $row['ItemCode'] . "<br>";
    echo "Description: " . $row['ItemDescription'] . "<br>";
    echo "Quantity on Hand: " . $row['QuantityOnHand'] . "<br><br>";
}

// Close the connection
odbc_close($conn);
?>

In this code, you start by defining the DSN and credentials needed to connect to the Sage 100 database. The odbc_connect() function establishes the connection, and the odbc_exec() function executes the SQL query to retrieve item data. The results are then fetched and displayed using a loop.

Verifying API Call Success and Handling Errors

After running the code, verify the success of your API call by checking the output. The retrieved item data should match the records in your Sage 100 test environment.

To handle errors effectively, ensure you use error-checking functions like odbc_errormsg() to capture and display any issues during the connection or query execution. Implementing try-catch blocks can also help manage exceptions gracefully.

By following these steps, you can efficiently retrieve item data from Sage 100 using PHP, enabling seamless integration and automation of inventory management tasks.

Sage 100 API call documentation page.

Conclusion and Best Practices for Using Sage 100 API with PHP

Integrating with the Sage 100 API using PHP provides a powerful way to automate and streamline inventory management tasks. By following the steps outlined in this guide, developers can efficiently retrieve item data and incorporate it into custom applications or reporting tools.

Best Practices for Secure and Efficient API Integration

  • Securely Store Credentials: Always store your Sage 100 credentials securely. Consider using environment variables or secure vaults to prevent unauthorized access.
  • Handle Rate Limiting: Be mindful of any rate limits imposed by the Sage 100 API. Implement retry logic and exponential backoff strategies to handle rate limit errors gracefully.
  • Data Transformation and Standardization: Ensure that data retrieved from Sage 100 is transformed and standardized to fit your application's requirements. This can help maintain data consistency across different systems.
  • Error Handling: Implement robust error handling using try-catch blocks and logging mechanisms to capture and resolve issues promptly.

Streamlining Integration with Endgrate

For developers looking to simplify their integration processes, Endgrate offers a unified API solution that connects to multiple platforms, including Sage 100. By leveraging Endgrate, you can save time and resources, allowing you to focus on your core product development while ensuring a seamless integration experience for your customers.

Explore how Endgrate can enhance your integration capabilities by visiting Endgrate and discover the benefits of a streamlined, efficient integration process.

Read More

Ready to get started?

Book a demo now

Book Demo