---
title: Log Events with the REST Log API – Base URL, OAuth 2.0, and Code Samples
description: Post Log Events to the Nodinite v7 Log API from scripts and code. Find the base URL, explore operations in Scalar or Swagger, protect the Log API with OAuth 2.0 client credentials, and use samples in PowerShell, curl, C#, Python, and Node.js.
---

# Logging using the REST Log API

Your own applications, scripts, and integration platforms can send [Log Events][Log Event] straight to the :Nodinite: [Log API][]. Each **REST** call posts one Log Event, or a batch, as JSON, and :Nodinite: stores it in the [Log Databases][] where your [Log Views][] find it.

This page is the starting point for logging from code. It explains the base URL, how the Log API is protected, how to explore the operations in Scalar or Swagger, and gives samples in PowerShell, curl, C#, Python, and Node.js.

* ✅ Post single Log Events or batches over **REST** with a **JSON** payload  
* ✅ Validate a Log Event before you send it  
* ✅ Protect the Log API with **OAuth 2.0** client credentials when you need to  
* ✅ Explore and test every operation in **Scalar** or **Swagger**  

![Post a Log Event from Scalar and find it in a Log View, animated walkthrough (7.12)][3]  
*Animated walkthrough: a Log Event posted with Scalar's **Test Request** is found in a Log View on its order number.*  

>[!TIP]
>For high volumes, or when the Log API must not slow down your application, write the Log Events to a folder or queue and let the [Pickup Log Events Service][Pickup Service] deliver them. It retries automatically.

## :fa-diagram-project: Understanding Logging over REST

<div class="mermaid">
graph LR
    App["fa:fa-code Your application<br/>or script"]
    IdP["fa:fa-id-card Identity provider<br/>only when protected"]
    API["fa:fa-cloud-arrow-down Log API<br/>/LogAPI/api/LogEvent"]
    DB["fa:fa-database Log Databases"]
    LV["fa:fa-search Log Views"]
    App -->|1. Get token| IdP
    App -->|2. POST JSON Log Event| API
    API --> DB
    DB --> LV
    style API fill:#2678BD,color:#fff
    style IdP fill:#9E59BB,color:#fff
    style DB fill:#3F827B,color:#fff
</div>

*Your application posts JSON Log Events to the Log API (blue). When the Log API is protected, the application first gets an access token from the identity provider (purple). The events are stored in the Log Databases (green) and shown in Log Views.*

### :fa-puzzle-piece: Key Components

| Component | Role |
| --- | --- |
| [Log API][] | Receives Log Events over REST and stores them. Each environment has its own Log API web site and port. |
| [JSON Log Event][Json Formatted] | The payload; its page describes every field. |
| **Protection** | Off by default: the [Log API][] uses Anonymous Authentication. When you turn on **Enable Authentication** in the [Portal][Portal Auth Log API], every request needs an OAuth 2.0 bearer token. |
| **Scalar** and [Swagger][] | Interactive API references at the root of the [Log API][] web site. Use them to find operations, see the models, and test calls. |

## :fa-link: Find the Base URL {#find-the-base-url}

In :Nodinite: v7, each environment's Log API is its own [IIS][] web site with its own port. The Log API operations are under `/LogAPI/` on that site. The port is set for each environment in the :Nodinite: Portal, under **Core platform services** in the [Servers step][], so yours probably differs from the examples.

| What | URL | Example |
| --- | --- | --- |
| [Log API][] base URL | `https://{host}:{port}/LogAPI/` | `https://nodinite.contoso.com:40002/LogAPI/` |
| Post a [Log Event][] | `<base URL>api/LogEvent` | `https://nodinite.contoso.com:40002/LogAPI/api/LogEvent` |
| **Post a batch** | `<base URL>api/LogEvent/Batch` | `https://nodinite.contoso.com:40002/LogAPI/api/LogEvent/Batch` |
| **Validate without storing** | `<base URL>api/LogEvent/Validate` and `api/LogEvent/Batch/Validate` | `https://nodinite.contoso.com:40002/LogAPI/api/LogEvent/Validate` |
| **Scalar** (recommended) | `https://{host}:{port}/scalar` | `https://nodinite.contoso.com:40002/scalar` |
| **Swagger** | `https://{host}:{port}/swagger` | `https://nodinite.contoso.com:40002/swagger` |
| **Health check endpoint** | `https://{host}:{port}/isalive`, also `/LogAPI/isalive` | `https://nodinite.contoso.com:40002/isalive` |

>[!NOTE]
>Log agents and the [Pickup Service][] ask for the **Log API base URL**, ending in `/LogAPI/`. Scalar and Swagger are at the root of the site, without `/LogAPI/`. The health check answers `true` without credentials, so a load balancer or monitoring probe can call it. Always use **HTTPS** in production.

## :fa-magnifying-glass: Explore Operations in Scalar or Swagger {#explore-operations}

Both API references list every operation with its request and response models, and let you send test requests. Besides the POST operations, they list three lookups, `EndPointTypes`, `EndPointDirection`, and `EventDirection`, that return the valid values. Scalar also generates code snippets in many languages; add authentication yourself when the Log API is protected. Swagger may be removed in a future version, so prefer Scalar.

![Scalar showing POST /LogAPI/api/LogEvent with a C# HttpClient snippet and example response (7.12)][1]  
*Scalar shows the Log Event operation with a sample payload, a generated code snippet, and the response for each status code.*  

![Swagger showing POST /LogAPI/api/LogEvent with an editable sample request body (7.12)][2]  
*In Swagger, open the **LogEvent** group first; **Try it out** then fills in a sample Log Event that you can edit and send.*  

### Post a Test Event and Find It

Scalar sends its test requests to the Log API the page was opened from, so you can try a Log Event without writing code. The walkthrough at the top of this page does this:

1. Open `https://{host}:{port}/scalar` and select **POST** `/LogAPI/api/LogEvent`.
2. Select **Test Request**, replace the sample body with your Log Event, and select **Send**. The answer is `200 OK` with the receipt described under JSON Payload and Response below.
3. In the [Web Client][], open a [Log View][Log Views] that shows the event's [Message Type][Message Types], enter a value from the event's `Context` in a [Search Field][Search Fields], and select **Search**.

The [Logging Service][] processes new events in the background, so allow up to about 30 seconds before the event shows up in the Log View.

## :fa-shield-halved: Choose How to Protect the Log API {#protect-the-log-api}

| | Unprotected (default) | Protected with OAuth 2.0 |
| --- | --- | --- |
| [Portal][Portal Auth Log API] setting | **Enable Authentication** cleared | **Enable Authentication** checked, with the [Log API][] **Audiences** |
| What the caller sends | Only the JSON payload | `Authorization: Bearer <access token>` plus the payload |
| How the caller gets access | Network access to the [Log API][] | A client app registration using the OAuth 2.0 [client credentials][Protect Log API] grant |
| [Pickup Service][] setting | **Protected** cleared | **Protected** checked |
| Requires | Nothing | :Nodinite: running in [OpenID Connect / OAuth 2.0 mode][Install Nodinite v7 - OpenID] |
| Use when | The [Log API][] is only reachable from trusted networks | Callers run outside your trusted network, or your policy requires authenticated logging |

You set both values in the :Nodinite: Portal, in [Step 2: Auth › Log API][Portal Auth Log API]; the fields are described in [OAuth Log API settings][Log API OAuth settings].

### Set Up a Client for a Protected Log API

The Log API has its own app registration and audience, separate from the [Web API][Managing the Web API]. In short:

1. Register the Log API (**logApi**) in Microsoft Entra ID, set its **Application ID URI**, and set its access token version to `2`.
2. Register one client app per system that sends Log Events.
3. In the Portal, add the logApi **Application (client) ID** (not the `api://` URI) to **LogAPI.2 – Audiences**, and check **LogAPI.1 – Enable Authentication**.
4. The logging client requests a token with the scope `api://<logapi-client-id>/.default` and sends it as a bearer token.
5. In production, harden the setup: add the `AppRole_LogApi_write` app role, grant it to each approved client, and set **Assignment required** on logApi. Without this, any app registration in your tenant can get a Log API token.

:fa-shield-halved: Follow the step-by-step guide with screenshots: [Protect the Log API with OAuth 2.0 and Entra ID][Protect Log API].

>[!WARNING]
>Don't use the installation client (`NodiniteInstallationClient`) for your own logging. Give each calling system its own client, so you can rotate or revoke it on its own.

## :fa-file-code: JSON Payload and Response

Post Log Events as [JSON formatted Log Events][Json Formatted]. At minimum, provide the mandatory fields:

```json
{
  "LogAgentValueId": 42,
  "EndPointName": "INT101: My Integration",
  "EndPointUri": "https://api.example.com/orders",
  "EndPointDirection": 0,
  "EndPointTypeId": 50,
  "OriginalMessageTypeName": "Orders.Customer/1.0",
  "LogDateTime": "2026-10-11T13:37:00.123Z"
}
```

A successful call returns `200` with the result for the Log Event:

```json
{
  "EventId": "123e4567-e89b-12d3-a456-426614174000",
  "EventNumber": 1,
  "Status": 0,
  "ErrorMessage": null
}
```

A `400` response means the payload is invalid. Use `api/LogEvent/Validate` while you develop, to check a payload without storing it. For valid values, see [Endpoint Directions][], [Endpoint Types][], and [Event Directions][].

## :fa-code: Code Examples {#code-examples}

The examples use these placeholders:

| Placeholder | Value |
| --- | --- |
| `<logapi-base-url>` | The Log API base URL, for example `https://nodinite.contoso.com:40002/LogAPI/` |
| `<tenant-id>`, `<client-id>`, `<client-secret>` | Your Entra ID tenant and the client app, only when the Log API is protected |
| `<logapi-client-id>` | The Application (client) ID of the logApi app registration, only when the Log API is protected |

### :fa-scroll: PowerShell

Use [Invoke-RestMethod][] to post the Log Event. Remove the token lines and the `-Headers` parameter when the Log API is unprotected.

```powershell
$logApiBaseUrl = '<logapi-base-url>'

# Only when the Log API is protected: get an access token
$token = (Invoke-RestMethod -Method Post `
    -Uri 'https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token' `
    -Body @{
        grant_type    = 'client_credentials'
        client_id     = '<client-id>'
        client_secret = $env:NODINITE_CLIENT_SECRET
        scope         = 'api://<logapi-client-id>/.default'
    }).access_token
$headers = @{ Authorization = "Bearer $token" }

$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('o')
    LogStatus               = 0
    LogText                 = 'Order processed successfully'
    Body                    = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('<Order>...</Order>'))
    Context                 = @{ OrderId = 'ORD-12345'; CustomerId = 'CUST-001' }
}

$response = Invoke-RestMethod -Method Post -Uri "${logApiBaseUrl}api/LogEvent" `
    -Headers $headers -ContentType 'application/json' `
    -Body ($logEvent | ConvertTo-Json -Depth 10)

"Logged event $($response.EventId), status $($response.Status)"
```

*Example: Post a Log Event from PowerShell.*

### :fa-terminal: curl

```bash
# Only when the Log API is protected
TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token" \
  -d "grant_type=client_credentials" -d "client_id=<client-id>" \
  -d "client_secret=$NODINITE_CLIENT_SECRET" -d "scope=api://<logapi-client-id>/.default" | jq -r .access_token)

curl -X POST "<logapi-base-url>api/LogEvent" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"LogAgentValueId":42,"EndPointName":"INT101: REST curl Integration","EndPointUri":"https://api.example.com/orders","EndPointDirection":0,"EndPointTypeId":50,"OriginalMessageTypeName":"Orders.Customer/1.0","LogDateTime":"2026-10-11T13:37:00.123Z"}'
```

*Example: Post a Log Event with curl. Leave out the `Authorization` header when the Log API is unprotected.*

### :fa-code: C\#

When the Log API is protected, get the token with MSAL as in the [Web API OAuth guide][Web API OAuth], using the scope `api://<logapi-client-id>/.default`, and set it on the `HttpClient`.

```csharp
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;

using var http = new HttpClient { BaseAddress = new Uri("<logapi-base-url>") };
// Only when the Log API is protected:
// http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

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 = DateTimeOffset.UtcNow,
    LogStatus = 0,
    LogText = "Order processed",
    Body = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Order>...</Order>")),
    Context = new Dictionary<string, string> { ["OrderId"] = "ORD-12345", ["CustomerId"] = "CUST-001" }
};

var response = await http.PostAsJsonAsync("api/LogEvent", logEvent);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

*Example: Post a Log Event from .NET with `HttpClient`.*

>[!TIP]
>For .NET, you can also use the `Nodinite.Libraries.Contracts.LogRestApi` NuGet package for typed Log Event contracts. See the [Hello World .NET sample][Hello World].

### :fab fa-python: Python

Install the dependency first: `pip install requests`.

```python
import base64
import datetime
import os
import requests

log_api_base_url = "<logapi-base-url>"
headers = {}

# Only when the Log API is protected
if os.environ.get("NODINITE_CLIENT_SECRET"):
    token = requests.post(
        "https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token",
        data={
            "grant_type": "client_credentials",
            "client_id": "<client-id>",
            "client_secret": os.environ["NODINITE_CLIENT_SECRET"],
            "scope": "api://<logapi-client-id>/.default",
        },
        timeout=30,
    ).json()["access_token"]
    headers["Authorization"] = f"Bearer {token}"

log_event = {
    "LogAgentValueId": 42,
    "EndPointName": "INT101: REST Python Integration",
    "EndPointUri": "https://api.example.com/orders",
    "EndPointDirection": 0,
    "EndPointTypeId": 50,
    "OriginalMessageTypeName": "Orders.Customer/1.0",
    "LogDateTime": datetime.datetime.now(datetime.timezone.utc).isoformat(),
    "Body": base64.b64encode(b"<Order>...</Order>").decode(),
    "Context": {"OrderId": "ORD-12345"},
}

response = requests.post(f"{log_api_base_url}api/LogEvent", json=log_event, headers=headers, timeout=30)
response.raise_for_status()
print(response.json())
```

*Example: Post a Log Event from Python.*

### :fab fa-node-js: Node.js

Requires Node.js 18 or later (built-in `fetch`).

```javascript
const logApiBaseUrl = '<logapi-base-url>';
const headers = { 'Content-Type': 'application/json' };

// Only when the Log API is protected
if (process.env.NODINITE_CLIENT_SECRET) {
  const tokenResponse = await fetch('https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token', {
    method: 'POST',
    body: new URLSearchParams({
      grant_type: 'client_credentials',
      client_id: '<client-id>',
      client_secret: process.env.NODINITE_CLIENT_SECRET,
      scope: 'api://<logapi-client-id>/.default'
    })
  });
  headers.Authorization = `Bearer ${(await tokenResponse.json()).access_token}`;
}

const response = await fetch(`${logApiBaseUrl}api/LogEvent`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    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(),
    Body: Buffer.from('<Order>...</Order>').toString('base64'),
    Context: { OrderId: 'ORD-12345' }
  })
});
console.log(response.status, await response.json());
```

*Example: Post a Log Event from Node.js.*

>[!IMPORTANT]
>Read client secrets from a vault or environment variable at run time. Never commit secrets to source control, and never log tokens.

## :fa-list-check: Best Practices

### Use Asynchronous Logging for Volume

For high-volume scenarios, or when network reliability is a concern, use the [Pickup Log Events Service][Pickup Service] instead of synchronous REST calls:

1. Write JSON Log Events to a file system folder or message queue.
2. Configure the [Pickup Service][] to read from that location.
3. Let :Nodinite: handle retries and processing.

This decouples your application from the logging infrastructure and improves resilience; see [Asynchronous Logging][]. To send many events at once over REST, post them to `api/LogEvent/Batch`.

### Include Context Properties

Use the `Context` field to add searchable business data:

```json
"Context": {
  "OrderId": "ORD-12345",
  "CustomerId": "CUST-001",
  "TotalAmount": "1234.56",
  "CorrelationId": "064205E2-F7CF-43A6-B514-4B55536C2B67"
}
```

This enables self-service [Log Views][] for business users without payload parsing. See [Context Options][] for the reserved keys that change how an event is processed, and [Repository Binding][] for the keys that populate the [Repository Model][]. Context properties that match the [ContextPropertiesFilters][] [System Parameter][System Parameters] are removed before they are stored; see [What happens after the Log API accepts an event][What Happens After].

### Handle Errors Gracefully

Always implement error handling and retry logic, and never let a logging failure stop your business process:

```powershell
try {
    Invoke-RestMethod -Method Post -Uri "${logApiBaseUrl}api/LogEvent" -Headers $headers `
        -ContentType 'application/json' -Body $jsonBody
} catch {
    Write-Warning "Failed to log event: $($_.Exception.Message)"
    # Retry, or write the event to a folder for the Pickup Service
}
```

### Base64 Encode Payloads

Always [base64 encode](https://www.base64encode.org/)<sup>:fa-arrow-up-right-from-square:</sup> message bodies:

```powershell
$body = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($xmlMessage))
```

## :fa-hand-point-right: Next Steps

* :fa-file-code: [JSON formatted Log Event][Json Formatted]  
* :fa-truck-pickup: [Pickup Log Events Service][Pickup Service]  
* :fa-bolt: [Log Event Overview][Log Event]  
* :fa-shield-halved: [OAuth Log API settings][Log API OAuth settings]  
* :fa-shield-halved: [Protect the Log API with OAuth 2.0 and Entra ID][Protect Log API]  
* :fa-list-ul: [Log API Scenarios][Scenarios]  

## :fa-link-horizontal: Related Topics

* :fa-key: [Call the Web API with OAuth 2.0 Client Credentials][Web API OAuth]  
* :fa-gears: [Managing the Web API][]  
* :fa-rocket: [Install Nodinite v7 - OpenID][]  
* :fa-shield-halved: [Register Nodinite Applications in Azure AD (Entra ID) with OpenID][Install Nodinite v7 - OpenID - EntraID]  
* :fa-search: [Log Views][]  
* :fa-tags: [Context Options][]  
* :fa-bolt: [Asynchronous Logging][]  
* :fa-hard-drive: [Logging Service][]  
* :fa-tombstone: [Log using WCF][]  

[1]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/LogEvent_Scalar.png
[2]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/LogEvent_Swagger.png
[3]:{ndm}/Documentation%20Pictures/IM/CoreServices/LogAPI/LogApi_PostEvent.gif

[Asynchronous Logging]:{ndr}/Core%20Services/Log%20API/Features/Asynchronous%20Logging.md
[Context Options]:{ndr}/Core%20Services/Log%20Event/Features/Context%20Options.md
[ContextPropertiesFilters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/ContextPropertiesFilters.md
[Endpoint Directions]:{ndr}/Core%20Services/Log%20Event/Features/Endpoint%20Directions.md
[Endpoint Types]:{ndr}/Core%20Services/Log%20Event/Features/Endpoint%20Types.md
[Event Directions]:{ndr}/Core%20Services/Log%20Event/Features/Event%20Directions.md
[Hello World]:{ndr}/Core%20Services/Log%20API/Troubleshooting/FAQ%20-%20Hello%20World%20-%20.NET%20Sample.md
[IIS]:{ndr}/Install%20and%20Update/Troubleshooting/IIS/IIS%20Windows%20Features.md
[Install Nodinite v7 - OpenID]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID.md
[Install Nodinite v7 - OpenID - EntraID]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID%20-%20EntraID.md
[Invoke-RestMethod]:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.1&viewFallbackFrom=powershell-6
[Json Formatted]:{ndr}/Core%20Services/Log%20Event/Features/JSON%20Log%20Event.md
[Log API]:{ndr}/Core%20Services/Log%20API/Overview.md
[Log API OAuth settings]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20-%20OpenID.md#oauth-log-api-settings
[Log Databases]:{ndr}/Core%20Services/Log%20Databases/Overview.md
[Log Event]:{ndr}/Core%20Services/Log%20Event/Overview.md
[Log using WCF]:{ndr}/Core%20Services/Log%20API/Features/Log%20using%20WCF.md
[Log Views]:{ndr}/Administration/1.%20Log%20Management/1.%20Log%20Views/Features/What%20is%20a%20Log%20View.md
[Logging Service]:{ndr}/Core%20Services/Logging%20Service/Overview.md
[Managing the Web API]:{ndr}/Core%20Services/Web%20API/Features/Managing%20the%20Web%20API.md
[Message Types]:{ndr}/Repository%20Model/Message%20Types/Overview.md
[Pickup Service]:{ndr}/Logging%20and%20Monitoring/Pickup%20LogEvents%20Service/Overview.md
[Portal Auth Log API]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/02%20-%20Auth.md#log-api
[Protect Log API]:{ndr}/Core%20Services/Log%20API/Scenarios/Protect%20the%20Log%20API%20with%20OAuth%202.0%20and%20Entra%20ID.md
[Repository Binding]:{ndr}/Core%20Services/Log%20Event/Features/Repository%20Binding.md
[Repository Model]:{ndr}/Repository%20Model/Overview.md
[Scenarios]:{ndr}/Core%20Services/Log%20API/Scenarios/Overview.md
[Search Fields]:{ndr}/Administration/1.%20Log%20Management/2.%20Search%20Fields/Features/What%20is%20a%20Search%20Field.md
[Servers step]:{ndr}/Install%20and%20Update/Getting%20started/Version%207/Install%20Nodinite%20v7%20Steps/04%20-%20Servers.md#core-platform-services
[Swagger]:https://swagger.io/
[System Parameters]:{ndr}/Administration/5.%20Settings/5.%20System%20Parameters/Overview.md
[Web API OAuth]:{ndr}/Core%20Services/Web%20API/Scenarios/Call%20the%20Web%20API%20with%20OAuth%202.0%20Client%20Credentials.md
[Web Client]:{ndr}/Core%20Services/Web%20Client/Overview.md
[What Happens After]:{ndr}/Core%20Services/Log%20API/Overview.md#what-happens-after