A comprehensive integration solution that automatically synchronizes SAP Business One documents (Invoices and Credit Notes) with the QuePagar platform. This solution provides both automated synchronization via a Windows Service and on-demand querying via a RESTful Web API.
- Automated Synchronization: Windows Service that runs on a configurable schedule
- RESTful API: On-demand document querying and synchronization
- Robust Delta Updates: Uses UDFs to track last sent timestamps, preventing data loss
- Comprehensive Error Handling: Detailed logging and error recovery
- JWT Authentication: Secure API access with token-based authentication
- SAP DI API Integration: Full integration with SAP Business One's Data Interface API
- Configurable: Easy configuration via appsettings.json files
- SAP Business One 10.0 or higher
- .NET 6.0 Runtime
- SQL Server (for SAP B1 database)
- Windows Server 2016 or higher (for Windows Service)
- QuePagar API access and credentials
The solution consists of four main components:
- SAPQuePagarModels: Data models and DTOs
- SAPQuePagarDataAccess: SAP DI API integration and data access layer
- SAPQuePagarService: Windows Service for automated synchronization
- SAPQuePagarWebAPI: RESTful Web API for on-demand operations
First, run the setup scripts to create the required User Defined Tables and Fields:
-- Run these scripts in your SAP B1 database
-- 1. CreateUserDefinedTables.sql
-- 2. CreateUserDefinedFields.sql (or use the DI API script)
Create the following UDFs in SAP Business One:
U_IsAffiliated
(Alphanumeric, 1 char, Y/N)U_QuePagarLastSync
(Date)
U_QuePagarLastSent
(Date)U_QuePagarStatus
(Alphanumeric, 20 chars)U_QuePagarError
(Alphanumeric, 255 chars)U_QuePagarDocId
(Alphanumeric, 50 chars)
U_QuePagarLastSent
(Date)U_QuePagarStatus
(Alphanumeric, 20 chars)U_QuePagarError
(Alphanumeric, 255 chars)U_QuePagarDocId
(Alphanumeric, 50 chars)
# Clone or download the solution
cd "SAP Business One Simple Program Development"
# Restore NuGet packages
dotnet restore
# Build the solution
dotnet build
Edit SAPQuePagarService/appsettings.json
:
{
"IntegrationConfig": {
"QuePagarApiKey": "YOUR_QUEPAGAR_API_KEY",
"QuePagarBaseUrl": "https://quepagar.com/api/v1",
"SAPServer": "YOUR_SAP_SERVER",
"SAPDatabase": "YOUR_SAP_DATABASE",
"SAPUsername": "YOUR_SAP_USERNAME",
"SAPPassword": "YOUR_SAP_PASSWORD",
"SyncIntervalMinutes": 30,
"JwtSecretKey": "YOUR_JWT_SECRET_KEY_AT_LEAST_32_CHARACTERS"
}
}
Edit SAPQuePagarWebAPI/appsettings.json
:
{
"IntegrationConfig": {
"QuePagarApiKey": "YOUR_QUEPAGAR_API_KEY",
"QuePagarBaseUrl": "https://quepagar.com/api/v1",
"SAPServer": "YOUR_SAP_SERVER",
"SAPDatabase": "YOUR_SAP_DATABASE",
"SAPUsername": "YOUR_SAP_USERNAME",
"SAPPassword": "YOUR_SAP_PASSWORD",
"JwtSecretKey": "YOUR_JWT_SECRET_KEY_AT_LEAST_32_CHARACTERS"
},
"JwtSettings": {
"SecretKey": "YOUR_JWT_SECRET_KEY_AT_LEAST_32_CHARACTERS",
"Issuer": "SAPQuePagarIntegration",
"Audience": "QuePagarAPI",
"ExpirationMinutes": 60
}
}
# Publish the service
dotnet publish SAPQuePagarService -c Release -o ./publish
# Install as Windows Service
sc create "SAPQuePagarIntegration" binPath="C:\path\to\publish\SAPQuePagarService.exe"
sc start "SAPQuePagarIntegration"
# Run the Web API
dotnet run --project SAPQuePagarWebAPI
# Or publish and run
dotnet publish SAPQuePagarWebAPI -c Release -o ./publish
dotnet ./publish/SAPQuePagarWebAPI.dll
- Open SAP Business One
- Go to Business Partners
- Edit a supplier and set
U_IsAffiliated
to "Y" - Add the supplier to the
@AFFILIATEDSUPPLIERS
table:
INSERT INTO [@AFFILIATEDSUPPLIERS]
(Code, Name, U_CardCode, U_CardName, U_IsActive, U_CreatedDate)
VALUES
('SUP001', 'Supplier 1', 'S00001', 'Supplier Name', 'Y', GETDATE())
Configure sync behavior in the @QUEPAGARSETTINGS
table:
-- Update sync interval (in minutes)
UPDATE [@QUEPAGARSETTINGS]
SET U_SettingValue = '15'
WHERE U_SettingKey = 'SyncIntervalMinutes'
-- Enable/disable logging
UPDATE [@QUEPAGARSETTINGS]
SET U_SettingValue = 'true'
WHERE U_SettingKey = 'EnableLogging'
Get a JWT token:
curl -X POST "https://your-api-url/api/auth/token" \
-H "Content-Type: application/json" \
-d '{
"username": "your_sap_username",
"password": "your_sap_password",
"company": "your_company"
}'
Query specific documents:
curl -X POST "https://your-api-url/api/documents/query" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"docIds": ["12345", "67890"]
}'
Sync specific documents with QuePagar:
curl -X POST "https://your-api-url/api/documents/sync" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"docIds": ["12345", "67890"]
}'
curl -X GET "https://your-api-url/api/documents/status" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"
Logs are written to the configured directory (default: C:\Logs\SAPQuePagarIntegration
):
SAPQuePagarService.log
- Windows Service logsSAPQuePagarWebAPI.log
- Web API logsIntegration.log
- Integration operation logs
The Windows Service logs to the Windows Event Viewer under:
- Source:
SAPQuePagarIntegration
- Log:
Application
- Web API Health:
GET /health
- Service Status: Check Windows Services console
-
SAP Connection Failed
- Verify SAP server credentials
- Check SAP server accessibility
- Ensure DI API is properly installed
-
QuePagar API Errors
- Verify API key is correct
- Check network connectivity
- Review API rate limits
-
Documents Not Syncing
- Check if suppliers are marked as affiliated
- Verify document status is "Open"
- Review UDF values
-
Service Won't Start
- Check configuration files
- Verify .NET 6.0 is installed
- Review Windows Event Log
Enable debug logging by setting:
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
}
}
- Windows Service runs on schedule
- Connects to SAP using DI API
- Queries affiliated suppliers from
@AFFILIATEDSUPPLIERS
table - Fetches documents where
UpdateDate > U_QuePagarLastSent
orU_QuePagarLastSent IS NULL
- Transforms documents to QuePagar format
- Sends to QuePagar API with authentication
- Updates UDFs only on successful transmission
- Logs results for monitoring
- JWT tokens for API authentication
- SAP credentials validation
- Configurable CORS policies
- Secure configuration management
- No hardcoded credentials
- Configurable batch sizes
- Efficient delta updates
- Connection pooling
- Async operations
- Memory management
For support and questions:
- Check the troubleshooting section
- Review log files
- Contact the development team
- Submit issues via the project repository
This project is proprietary software. All rights reserved.
Version: 1.0.0
Last Updated: December 2024
Compatibility: SAP Business One 10.0+, .NET 6.0+