Getting Started with JTL API Integration

Introduction

This guide will help you set up and configure the JTL API integration using the UnityContainer. The code snippet provided will register an instance of ApiSettings with the container, allowing you to configure and manage your connection settings to the JTL ERP system.

Prerequisites

Before getting started, ensure you have the following:

  • .NET framework or .NET Core installed on your development environment.
  • Access credentials for the JTL ERP system, including database information and user credentials.

Setup Instructions

  1. Install ApiService

    First, make sure you have the ApiService library installed in your project. You can install it via NuGet with the following command:

     Install-Package T4dt.JtlModel.ApiService
    

    The depending packages will be installed automatically.

  2. Define Your API Settings

    Create an instance of ApiSettings and configure the necessary parameters to connect to your JTL ERP system. The following code snippet demonstrates how to set up these settings:

    var container = new UnityContainer();
    container.RegisterInstance(new ApiSettings
    {
        OrderPrefix = "test_",
        WawiUserName = "Test",
        ApplicationName = "ApplicationName",
        DatabaseName = "DatabaseNameOfWawi",
        DatabaseServer = "DatabaseServerOfWawi",
        Password = "abcUser",
        Username = "testPw",
        JtlWawiVersion = Version.Parse("1.5"),
        TrustServerCertificate = true
    });
    
     container.LoadJtlDbServiceModule();
    

    In this configuration:

    • OrderPrefix specifies a prefix for orders. You'll find the order in the Wawi with this prefix.D
    • WawiUserName and Password are the credentials for the ERP system.
    • ApplicationName identifies your application.
    • DatabaseName and DatabaseServer are used to connect to the JTL database.
    • Username and Password are used for authentication.
    • JtlWawiVersion specifies the version of JTL Wawi you are connecting to.
    • TrustServerCertificate is a boolean value that determines whether to trust the server certificate, to prevent exceptions when connecting to the database, if the certificate is not trusted or outdated.
    • LoadJtlDbServiceModule() initialize the module, checks and prepares the database. Runs Rollup migrations etc.. It is importand to load this module before using any endpoint. Make sure to call this method after registering or changing the ApiSettings instance.
  3. Integrate with Your Application

    Use the configured container instance throughout your application to resolve dependencies and manage API interactions.

    Only use depedndency injection to resolve the endpoint interfaces. Do not resolve the endpoint itself.

    This setup helps maintain clean, testable code by decoupling the configuration details from the business logic. The service will then handle all the version specific.dependencies.

    Example: Get an order by Id:

public class OrderService{
    private readonly IOderEndpoint _orderEndpoint;
    public OrderService(IOderEndpoint orderEndpoint)
    {
        _orderEndpoint = orderEndpoint;
    }    
	Order order = await _orderEndpoint.GetByIdAsync(1);
}

Conclusion

You are now set up with the initial configuration for integrating with the JTL API. This setup is a foundational step, enabling further development and customization according to your specific business needs. Ensure to secure sensitive information like passwords and database credentials appropriately within your application.