Retrieving DataMiner data
You can load the elements in a view with an HTTP request and keep the display current with a WebSocket subscription. Both go through the DataMiner network bridge, which uses the existing signed-in session. The iframe does not connect to the API directly or handle sign-in credentials.
The bridge accepts same-origin endpoints under /API/v1/, so a path such as /API/v1/Json.asmx/GetElementsLiteForView works without a hostname. You can look up endpoints in the Web Services API v1 method overview or in the OpenAPI and AsyncAPI specifications on your DataMiner System at /API/docs/http.json and /API/docs/ws.json.
Connecting to the bridge
Use one MessageChannel for both HTTP requests and WebSockets. The id field ties each reply to a request or socket. It is a nonblank string of up to 128 characters and must be unique among pending requests and opening or active sockets. To abort a request, send data to a socket, or close a socket, use the original ID.
function connectBridge(onReady) {
const channel = new MessageChannel();
const port = channel.port1;
const timer = setTimeout(() => {
port.close();
console.error("The DataMiner network bridge did not respond.");
}, 5000);
// Wait for { network: { type: "ready", version: 1 } } before using the port.
port.onmessage = event => {
const reply = event.data?.network;
if (reply?.type !== "ready") return;
clearTimeout(timer);
if (reply.version !== 1) {
port.close();
console.error("Unsupported DataMiner network bridge version.");
return;
}
onReady(port);
};
// Transfer exactly one port to the host and keep port1 for the app.
window.parent.postMessage(
{ network: { action: "connect" } },
"*",
[channel.port2]
);
}
// Replace 42 with your view ID. loadElements is defined in the HTTP example below.
const start = () => connectBridge(port => loadElements(port, 42));
// Defer the connection until the host finishes handling the iframe's load event.
if (document.readyState === "complete") {
setTimeout(start, 0);
} else {
window.addEventListener("load", () => setTimeout(start, 0), { once: true });
}
Making an HTTP request
type FetchCommand = {
id: string;
action: "fetch";
url: string;
method?: string;
headers?: Record<string, string>;
body?: string | ArrayBuffer | Blob;
};
type FetchResult = {
id: string;
type: "fetch";
status: number;
statusText: string;
headers: Record<string, string>;
body: ArrayBuffer;
url: string;
};
An HTTP request goes to the port as { network: command }. The reply arrives as { network: result } with the same ID. The method defaults to GET. A JSON POST to an *.asmx method uses Content-Type: application/json and a JSON object serialized as a string. The host adds connection as an empty GUID and uses the signed-in session, so that field is not needed in the request body.
This example uses GetElementsLiteForView:
let nextRequestID = 0;
function loadElements(port, viewID) {
const id = `load-elements-${++nextRequestID}`;
const timer = setTimeout(() => {
port.removeEventListener("message", onReply);
console.error("Timed out waiting for the elements response.");
}, 125000);
function onReply(event) {
const result = event.data?.network;
// Other requests and sockets can receive replies on this same port.
if (result?.id !== id || !["fetch", "error"].includes(result.type)) return;
clearTimeout(timer);
port.removeEventListener("message", onReply);
if (result.type === "error") {
console.error(result.name, result.message);
} else if (result.status < 200 || result.status >= 300) {
console.error(`GetElementsLiteForView failed: HTTP ${result.status}.`);
} else {
try {
// The bridge returns bytes without changing the ASMX response format.
const text = new TextDecoder().decode(result.body);
const { d: elements } = JSON.parse(text);
if (!Array.isArray(elements)) throw new Error("Expected an array of elements.");
console.log(elements);
} catch (error) {
console.error("Could not decode the elements response.", error);
}
}
}
port.addEventListener("message", onReply);
port.postMessage({
network: {
id,
action: "fetch",
url: "/API/v1/Json.asmx/GetElementsLiteForView",
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
viewID,
includeSubViews: false,
includeServices: false,
includeRedundancyGroups: false
})
}
});
}
To cancel a pending request, send { network: { id, action: "abort" } }.
Opening a WebSocket for live updates
WebSocket commands use the same { network: command } envelope as HTTP requests:
type WebSocketCommand =
| { id: string; action: "ws-open"; url: string; protocols?: string | string[] }
| { id: string; action: "ws-send"; data: string | ArrayBuffer | Blob }
| { id: string; action: "ws-close"; code?: number; reason?: string };
The bridge forwards data without converting it to JSON. The WebSocket API reference describes what each subscription expects in that payload.
For ws-close, code defaults to 1000. The bridge accepts 1000 or an integer from 3000 through 4999. The reason defaults to an empty string and must not exceed 123 UTF-8 bytes.
Socket events arrive as { network: { id, type: "websocket", event, ... } }. The open event includes protocol and extensions, message includes data, and close includes code, reason, and wasClean.
let nextSocketID = 0;
// Call this from the bridge's onReady callback to check the connection.
function openDataSocket(port) {
const id = `data-socket-${++nextSocketID}`;
let opened = false;
const timer = setTimeout(() => {
stopListening();
closeSocket();
console.error("Timed out waiting for the DataMiner WebSocket to open.");
}, 35000);
function stopListening() {
clearTimeout(timer);
port.removeEventListener("message", onSocketReply);
}
function closeSocket() {
port.postMessage({ network: { id, action: "ws-close" } });
}
function onSocketReply(event) {
const reply = event.data?.network;
if (reply?.id !== id) return;
if (reply.type === "error") {
if (!opened) stopListening();
console.error(reply.name, reply.message);
return;
}
if (reply.type !== "websocket") return;
if (reply.event === "open") {
opened = true;
clearTimeout(timer);
// Ping checks the connection; the reply contains "Pong" in its Data field.
port.postMessage({
network: {
id,
action: "ws-send",
data: JSON.stringify({ ClientSubscriptionID: 0, Method: "Ping", Parameters: {} })
}
});
} else if (reply.event === "message") {
console.log("DataMiner WebSocket message:", reply.data);
} else if (reply.event === "error") {
console.error("The DataMiner WebSocket reported an error.");
} else if (reply.event === "close") {
stopListening();
}
}
port.addEventListener("message", onSocketReply);
port.postMessage({ network: { id, action: "ws-open", url: "/API/v1/WebSocket.ashx" } });
// Call the returned function when the app no longer needs the socket.
return closeSocket;
}
Multiple subscriptions can share one socket.
Error messages
If the app sends an invalid handshake or sends another network command to window.parent, the host sends a window message with type: "error". Its message is Network commands require a connected MessagePort. Transfer one port with { network: { action: "connect" } }. All network commands other than the handshake go to the connected port.
On the port, the bridge replies with { network: { id, type: "error", name, message } }. The id is empty if the bridge cannot identify the command. HTTP error statuses, such as 404, still arrive as fetch results. A WebSocket can also send a websocket event with event: "error" and no diagnostic message.
For the thresholds behind QuotaExceededError and TimeoutError, see Network bridge limits.
| Name | Message | Meaning |
|---|---|---|
Error |
A network message requires a network command. |
The port message is missing the network command object. |
Error |
The network message could not be deserialized. |
The bridge could not read the message sent over the port. |
Error |
A network command requires a nonempty string id of at most 128 characters. |
The command ID is missing, blank, not a string, or too long. |
Error |
A network operation with this id already exists. |
Another pending request or socket already uses this ID. |
Error |
Invalid network command. |
The action is unrecognized or has invalid arguments. Check that the ID refers to an operation in the right state, such as an open socket for ws-send. |
Error |
Fetch failed. Check the wrapper network panel. |
The bridge could not complete the fetch. |
Error |
WebSocket could not be opened. Check the wrapper network panel. |
The bridge could not open the socket. |
Error |
WebSocket data could not be sent. Check the wrapper network panel. |
The bridge could not send data through the socket. |
AbortError |
Fetch aborted. |
The pending HTTP request was canceled. |
TimeoutError |
The HTTP request timed out. |
The request did not finish within the allowed time, including time spent waiting in the queue. |
TimeoutError |
The WebSocket connection timed out. |
The connection did not open within the allowed time. |
InvalidStateError |
A WebSocket for this API endpoint already exists. Reuse its handle through one shared client. |
The app already has a socket opening or open for this endpoint. |
SecurityError |
Only same-origin API URLs are allowed. |
The destination does not match the host origin. |
SecurityError |
The API URL is not registered. |
The path is not under an API prefix the bridge serves. |
SecurityError |
Ambiguous API paths are not allowed. |
The URL path could not be interpreted unambiguously. Use the documented path. |
SecurityError |
This API method is not allowed. |
The method cannot be called through the bridge. |
SecurityError |
ASMX calls require an explicit method URL; SOAP is not supported.SOAP requests are not supported. |
Use the JSON endpoint and include the method name in the URL. |
QuotaExceededError |
The network URL is too long.The request headers exceed the bridge limit. |
The URL or HTTP headers exceed a bridge limit. |
QuotaExceededError |
Too many WebSocket protocols.The WebSocket protocols exceed the header limit. |
The WebSocket protocol list has too many entries or is too long. |
QuotaExceededError |
The HTTP request queue is full.The network operation queue is full. |
The bridge cannot queue another operation. |
QuotaExceededError |
Too many WebSocket connections. |
The app has reached the connection limit. |
QuotaExceededError |
The outgoing payload exceeds the bridge limit.The pending payload buffer is full.The WebSocket send buffer is full. |
The data or the amount already waiting to be sent exceeds a bridge limit. |
Network bridge limits
The limits listed below apply to each app's network bridge. HTTP and WebSocket traffic have separate rate limits, each measured over a rolling one-second window. Requests and operations wait in their respective queues when they cannot start immediately.
| What the bridge limits | Limit |
|---|---|
| HTTP requests started | 20 per second |
| Active HTTP requests | 50, including requests whose response bodies are still being downloaded |
| Queued HTTP requests | 200, with at most 250 active and queued requests combined |
| WebSocket operations started | 500 per second, counting connection attempts and outgoing messages together |
| Queued WebSocket operations | 2,000 |
| WebSocket connections | 4, including connections still opening |
| HTTP request body | 1 MiB (1,048,576 bytes), measured before the bridge adds connection |
| Outgoing WebSocket message | 1 MiB |
| Pending outgoing data | 4 MiB (4,194,304 bytes) shared across HTTP request bodies and WebSocket sends |
| WebSocket send buffer | 1 MiB per socket, including data already buffered by the browser and the next message |
| Network URL | 8,192 characters |
| Command ID | 128 characters |
| HTTP headers | 32 entries and 16,384 characters across all names and values |
| WebSocket subprotocols | 32 entries and 16,384 characters across all names |
| HTTP request deadline | 120 seconds, including queue time and response-body download |
| WebSocket connection deadline | 30 seconds, including queue time |
Character limits use JavaScript string length. For payload limits, the bridge measures strings in UTF-8 bytes and binary payloads by their byte size.