Logging using the REST Log API
Integrate your applications with Nodinite by logging events through the REST-based Log API. This guide provides code samples in multiple languages for both Windows Authentication and OAuth 2.0, enabling you to implement robust logging in your custom solutions.
What you'll find on this page:
✅ REST-based logging with Windows Authentication or OAuth 2.0
✅ Code samples in PowerShell, C#, Java, and Node.js
✅ Nodinite v7 URL structure and endpoints
✅ JSON payload examples and best practices
✅ Tips for asynchronous logging and error handling
Tip
For asynchronous, decoupled logging, consider using the Pickup Log Events Service instead. Drop JSON files to a folder or queue, and let Nodinite pick them up automatically.
Authentication Methods
Nodinite v7 supports two authentication methods for REST-based logging:
- Windows Authentication (NTLM/Kerberos) - Traditional on-premises authentication using Windows credentials
- OAuth 2.0 / OpenID Connect (OIDC) - Modern authentication for cloud-based deployments with enhanced security
For detailed OAuth configuration, see Install Nodinite v7 - OpenID.
Nodinite v7 URL Structure
Nodinite v7 introduces a simplified URL structure for the Log API:
| Endpoint | URL Pattern | Example |
|---|---|---|
| Log Event | https://{host}/logapi/api/logevents |
https://nodinite.local:41000/logapi/api/logevents |
Tip
The new URL structure removes the application path segment (e.g.,
/Nodinite/Demo/) used in earlier versions.
JSON Payload Structure
All Log Events must be posted as JSON formatted Log Events. At minimum, provide these mandatory fields:
{
"LogAgentValueId": 42,
"EndPointName": "INT101: My Integration",
"EndPointUri": "https://api.example.com/orders",
"EndPointDirection": 0,
"EndPointTypeId": 50,
"OriginalMessageTypeName": "Orders.Customer/1.0",
"LogDateTime": "2025-10-27T13:37:00.123Z"
}
For complete field definitions and examples, see JSON formatted Log Event.
Code Examples
Powershell
You can easily use Invoke-RestMethod to post Log Events to the Log API.
Windows Authentication
# Nodinite v7 Log API endpoint
$logApiUrl = "https://nodinite.local:41000/logapi/api/logevents"
# Create Log Event payload
$logEvent = @{
LogAgentValueId = 42
EndPointName = "INT101: REST PowerShell Integration"
EndPointUri = "https://api.example.com/orders"
EndPointDirection = 0
EndPointTypeId = 50
OriginalMessageTypeName = "Orders.Customer/1.0"
LogDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
LogStatus = 0
LogText = "Order processed successfully"
Body = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("<Order>...</Order>"))
Context = @{
OrderId = "ORD-12345"
CustomerId = "CUST-001"
}
}
# Post to Log API
$response = Invoke-RestMethod -Uri $logApiUrl -Method Post -Body ($logEvent | ConvertTo-Json -Depth 10) -ContentType "application/json" -UseDefaultCredentials
Write-Host "Log Event created with ID: $($response.LogEventId)"
Example: Post a Log Event using Windows Authentication in Nodinite v7.
OAuth 2.0 / OpenID Connect
# Nodinite v7 Log API with OAuth 2.0
$logApiUrl = "https://nodinite.local:41000/logapi/api/logevents"
# OAuth configuration
$tokenEndpoint = "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token"
$clientId = "nodinite-prod-installation"
$clientSecret = "{your-client-secret}"
$scope = "api://nodinite-prod-logapi/.default"
# Get access token
$tokenBody = @{
client_id = $clientId
client_secret = $clientSecret
scope = $scope
grant_type = "client_credentials"
}
$tokenResponse = Invoke-RestMethod -Uri $tokenEndpoint -Method Post -Body $tokenBody -ContentType "application/x-www-form-urlencoded"
# Create Log Event payload (see above for structure)
$logEvent = @{
LogAgentValueId = 42
EndPointName = "INT101: REST OAuth Integration"
# ... other fields
LogDateTime = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
}
# Post with bearer token
$headers = @{ Authorization = "Bearer $($tokenResponse.access_token)" }
$response = Invoke-RestMethod -Uri $logApiUrl -Method Post -Body ($logEvent | ConvertTo-Json -Depth 10) -ContentType "application/json" -Headers $headers
Write-Host "Log Event created with ID: $($response.LogEventId)"
Example: Post a Log Event using OAuth 2.0 authentication in Nodinite v7.
Important
Store client secrets securely using Azure Key Vault, HashiCorp Vault, or environment variables. Never commit secrets to source control.
cSharp
Windows Authentication
using Newtonsoft.Json;
using System;
using System.Net;
using System.Text;
namespace NodiniteRestLogging
{
class Program
{
static void Main(string[] args)
{
var logApiUrl = "https://nodinite.local:41000/logapi/api/logevents";
// Create Log Event
var logEvent = new
{
LogAgentValueId = 42,
EndPointName = "INT101: REST C# Integration",
EndPointUri = "https://api.example.com/orders",
EndPointDirection = 0,
EndPointTypeId = 50,
OriginalMessageTypeName = "Orders.Customer/1.0",
LogDateTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
LogStatus = 0,
LogText = "Order processed",
Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Order>...</Order>")),
Context = new { OrderId = "ORD-12345", CustomerId = "CUST-001" }
};
using (var client = new WebClient { UseDefaultCredentials = true })
{
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
var response = client.UploadString(logApiUrl, JsonConvert.SerializeObject(logEvent));
Console.WriteLine($"Response: {response}");
}
}
}
}
Example: Post a Log Event using Windows Authentication in Nodinite v7.
OAuth 2.0 / OpenID Connect
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace NodiniteRestLoggingOAuth
{
class Program
{
static async Task Main(string[] args)
{
// OAuth configuration
var tokenEndpoint = "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token";
var clientId = "nodinite-prod-installation";
var clientSecret = "{your-client-secret}";
var scope = "api://nodinite-prod-logapi/.default";
// Get access token
using var tokenClient = new HttpClient();
var tokenRequest = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret),
new KeyValuePair<string, string>("scope", scope),
new KeyValuePair<string, string>("grant_type", "client_credentials")
});
var tokenResponse = await tokenClient.PostAsync(tokenEndpoint, tokenRequest);
var tokenJson = await tokenResponse.Content.ReadAsStringAsync();
var accessToken = JsonConvert.DeserializeObject<dynamic>(tokenJson).access_token;
// Create Log Event
var logEvent = new
{
LogAgentValueId = 42,
EndPointName = "INT101: REST C# OAuth Integration",
EndPointUri = "https://api.example.com/orders",
EndPointDirection = 0,
EndPointTypeId = 50,
OriginalMessageTypeName = "Orders.Customer/1.0",
LogDateTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
};
// Post to Log API
using var apiClient = new HttpClient();
apiClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.ToString());
var content = new StringContent(JsonConvert.SerializeObject(logEvent), Encoding.UTF8, "application/json");
var response = await apiClient.PostAsync("https://nodinite.local:41000/logapi/api/logevents", content);
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
}
}
Example: Post a Log Event using OAuth 2.0 authentication in Nodinite v7.
Java
Node.js
Windows Authentication
// This example uses httpntlm (https://www.npmjs.com/package/httpntlm)
// Run: "npm install httpntlm --save" before running this script.
var httpntlm = require('httpntlm');
var logEvent = {
LogAgentValueId: 42,
EndPointName: "INT101: REST Node.js Integration",
EndPointUri: "https://api.example.com/orders",
EndPointDirection: 0,
EndPointTypeId: 50,
OriginalMessageTypeName: "Orders.Customer/1.0",
LogDateTime: new Date().toISOString(),
LogStatus: 0,
LogText: "Order processed",
Body: Buffer.from("<Order>...</Order>").toString('base64'),
Context: {
OrderId: "ORD-12345",
CustomerId: "CUST-001"
}
};
httpntlm.post({
url: 'https://nodinite.local:41000/logapi/api/logevents',
username: '{YourWindowsUsername}',
password: '{YourWindowsPassword}',
json: logEvent
}, function (err, res) {
if (err) return console.error(err);
console.log('Log Event created:', res.body);
});
Example: Post a Log Event using Windows Authentication in Nodinite v7.
Important
Your password should be protected. Use the Pre-Encrypt password feature in a real-world scenario.
OAuth 2.0 / OpenID Connect
// This example uses axios (https://www.npmjs.com/package/axios)
// Run: "npm install axios --save" before running this script.
const axios = require('axios');
const qs = require('querystring');
async function logEvent() {
try {
// OAuth configuration
const tokenEndpoint = 'https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token';
const clientId = 'nodinite-prod-installation';
const clientSecret = '{your-client-secret}';
const scope = 'api://nodinite-prod-logapi/.default';
// Get access token
const tokenResponse = await axios.post(tokenEndpoint, qs.stringify({
client_id: clientId,
client_secret: clientSecret,
scope: scope,
grant_type: 'client_credentials'
}), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
// Create Log Event
const logEventData = {
LogAgentValueId: 42,
EndPointName: "INT101: REST Node.js OAuth Integration",
EndPointUri: "https://api.example.com/orders",
EndPointDirection: 0,
EndPointTypeId: 50,
OriginalMessageTypeName: "Orders.Customer/1.0",
LogDateTime: new Date().toISOString(),
LogStatus: 0,
Context: {
OrderId: "ORD-12345"
}
};
// Post to Log API
const response = await axios.post(
'https://nodinite.local:41000/logapi/api/logevents',
logEventData,
{
headers: {
'Authorization': `Bearer ${tokenResponse.data.access_token}`,
'Content-Type': 'application/json'
}
}
);
console.log('Log Event created:', response.data);
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
}
}
logEvent();
Example: Post a Log Event using OAuth 2.0 authentication in Nodinite v7.
Important
Store client secrets securely using environment variables or a secrets management service. Never commit secrets to source control.
Best Practices
Use Asynchronous Logging
For high-volume scenarios or when network reliability is a concern, use the Pickup Log Events Service instead of synchronous REST calls:
- Write JSON Log Events to a file system folder or message queue
- Configure the Pickup Service to monitor that location
- Let Nodinite handle retries and processing automatically
This decouples your application from the logging infrastructure and improves resilience.
Include Context Properties
Use the Context field to add searchable business data:
"Context": {
"OrderId": "ORD-12345",
"CustomerId": "CUST-001",
"TotalAmount": "1234.56",
"CorrelationId": "064205E2-F7CF-43A6-B514-4B55536C2B67"
}
This enables powerful self-service Log Views for business users without requiring payload parsing.
Handle Errors Gracefully
Always implement error handling and retry logic:
try {
$response = Invoke-RestMethod -Uri $logApiUrl -Method Post -Body $jsonBody -ContentType "application/json" -UseDefaultCredentials
} catch {
Write-Error "Failed to log event: $($_.Exception.Message)"
# Implement retry logic or fallback to file-based logging
}
Base64 Encode Payloads
Always base64 encode message bodies:
$body = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($xmlMessage))
Next Step
JSON formatted Log Event - Complete field reference
Pickup Log Events Service - Asynchronous logging
Install Nodinite v7 - OpenID - OAuth configuration
Log Event Overview
Related Topics
Register Nodinite Applications in Azure AD (Entra ID) with OpenID
Managing the Web API - REST automation for repository management
Log Views - Create searchable views for business users
Context Options - Repository auto-population
Log using WCF - Deprecated WCF-based logging