Using the Sage 100 API to Get Customers (with PHP examples)

by Endgrate Team 2024-08-01 5 min read

Sage 100 homepage

Introduction to Sage 100 API

Sage 100 is a comprehensive ERP solution designed to help businesses manage their accounting, inventory, and operations efficiently. Known for its robust features and flexibility, Sage 100 is a popular choice among small to medium-sized enterprises looking to streamline their business processes.

Integrating with the Sage 100 API allows developers to access and manipulate critical business data, such as customer information. For example, a developer might use the Sage 100 API to retrieve customer details and integrate them into a custom CRM system, enhancing customer relationship management and improving business operations.

Setting Up a Test/Sandbox Account for Sage 100 API Integration

Before you can start integrating with the Sage 100 API, it's essential to set up a test or sandbox account. This environment allows developers to safely experiment with API calls without affecting live data. Follow these steps to configure your Sage 100 test account:

Install and Configure the Sage 100 ODBC Driver

To interact with the Sage 100 API, you need to install and configure the Sage 100 ODBC driver. This driver facilitates the connection between your application and the Sage 100 database.

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

Create a Sage 100 Test Environment

Once the ODBC driver is configured, set up a Sage 100 test environment to simulate real-world scenarios:

  • Ensure you have access to a Sage 100 test server or request a sandbox account from Sage if available.
  • Configure the server to run the client/server ODBC driver as an application or service, depending on your needs.
  • Follow the server and workstation configuration steps outlined in the Sage 100 documentation to ensure proper setup.

Generate API Credentials for Sage 100

With the test environment ready, generate the necessary API credentials to authenticate your requests:

  1. Log in to your Sage 100 account and navigate to the API settings section.
  2. Create a new application and note down the client ID and client secret.
  3. Ensure you have the appropriate permissions set for accessing customer data.

By following these steps, you'll have a fully functional test environment for experimenting with the Sage 100 API, allowing you to safely develop and test your integration solutions.

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

Making API Calls to Retrieve Customers from Sage 100 Using PHP

To interact with the Sage 100 API and retrieve customer data, you'll need to set up your PHP environment and use the ODBC connection. This section will guide you through the process of making API calls using PHP, ensuring you can efficiently access customer information from Sage 100.

Setting Up Your PHP Environment for Sage 100 API Integration

Before making API calls, ensure your PHP environment is correctly configured:

  • Install PHP 7.4 or later on your system.
  • Ensure the ODBC extension is enabled in your PHP configuration. You can do this by editing your php.ini file and uncommenting the line extension=odbc.
  • Restart your web server to apply the changes.

Connecting to Sage 100 Using ODBC in PHP

Once your environment is set up, you can establish a connection to the Sage 100 database using ODBC. Here's a sample code snippet to get you started:


// Define DSN and credentials
$dsn = 'DSN=Sage100DSN';
$username = 'your_username';
$password = 'your_password';

// Establish ODBC connection
$connection = odbc_connect($dsn, $username, $password);

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

echo 'Connected successfully to Sage 100!';

Replace your_username and your_password with your actual Sage 100 credentials. Ensure the DSN matches the one you configured in the ODBC Data Source Administrator.

Executing SQL Queries to Retrieve Customer Data from Sage 100

With the connection established, you can now execute SQL queries to retrieve customer data. Here's an example of how to fetch customer information:


// SQL query to select customer data
$query = "SELECT CustomerNo, CustomerName, AddressLine1, City, State, ZipCode FROM AR_Customer";

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

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

// Fetch and display the results
while ($row = odbc_fetch_array($result)) {
    echo 'Customer No: ' . $row['CustomerNo'] . '<br>';
    echo 'Name: ' . $row['CustomerName'] . '<br>';
    echo 'Address: ' . $row['AddressLine1'] . ', ' . $row['City'] . ', ' . $row['State'] . ' ' . $row['ZipCode'] . '<br><br>';
}

This code snippet retrieves customer numbers, names, and addresses from the Sage 100 database. Customize the SQL query to suit your specific data retrieval needs.

Handling Errors and Verifying API Call Success

It's crucial to handle errors gracefully and verify the success of your API calls:

  • Use odbc_errormsg() to capture and display error messages.
  • Check the result of your queries to ensure data is being retrieved correctly.
  • Test your queries in the Sage 100 test environment to confirm they return the expected results.

By following these steps, you can effectively make API calls to Sage 100 using PHP, enabling seamless integration with your business applications. For more detailed information, refer to the Sage 100 API documentation.

Sage 100 API call documentation page.

Conclusion and Best Practices for Sage 100 API Integration Using PHP

Integrating with the Sage 100 API using PHP provides a powerful way to access and manage customer data, enhancing your business operations and customer relationship management. By following the steps outlined in this guide, you can efficiently set up your environment, establish a connection, and execute queries to retrieve valuable customer information.

Best Practices for Secure and Efficient Sage 100 API Usage

  • Secure Credentials: Store your Sage 100 credentials securely, using environment variables or a secure vault, to prevent unauthorized access.
  • Handle Errors Gracefully: Implement robust error handling using odbc_errormsg() to capture and log errors for troubleshooting.
  • Optimize Queries: Ensure your SQL queries are optimized for performance, especially when dealing with large datasets.
  • Test Thoroughly: Always test your integration in a sandbox environment to verify functionality and prevent disruptions in live systems.
  • Monitor Rate Limits: Be aware of any rate limits imposed by Sage 100 and implement strategies to handle them effectively.

Enhance Your Integration Strategy with Endgrate

While integrating with Sage 100 directly can be effective, leveraging a tool like Endgrate can streamline the process further. Endgrate allows you to manage multiple integrations through a unified API, saving time and resources. By outsourcing integrations to Endgrate, you can focus on your core product development and provide a seamless integration experience for your customers.

Explore the possibilities with Endgrate and discover how it can simplify your integration strategy. Visit Endgrate to learn more and start optimizing your integration processes today.

Read More

Ready to get started?

Book a demo now

Book Demo