Query Graph Data
Query specific parts of the graph using JSONQuery, a simple query language for filtering and transforming JSON data.
Endpoint
POST /graph/:job_id
Example Request
curl -X POST "https://api.example.com/graph/123" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query": ".pid_graph.nodes | filter(.node_type == \"pid_component\")"}'
Request Body
{
"query": ".pid_graph.nodes | filter(.node_type == \"pid_component\")"
}
Response
{
"query": ".pid_graph.nodes | filter(.node_type == \"pid_component\")",
"schema_version": "1",
"change_version": "1",
"result": [
{
"tag": "FV-101",
"id": "abc-123",
"node_type": "pid_component",
"node_classification": "piping_component.gate_valve"
}
]
}
Query Syntax
Queries start with a path and can be chained with operations using |.
Basic Path Access
.pid_graph.nodes # Get all nodes
.pid_graph.edges # Get all edges
.pid_graph.metadata # Get metadata
Filter
Filter items based on a condition:
.pid_graph.nodes | filter(.node_type == "pid_component")
.pid_graph.nodes | filter(.tag != "")
.pid_graph.edges | filter(.edge_type == "has_a")
Map
Extract specific fields:
.pid_graph.nodes | map(.tag)
.pid_graph.nodes | map({id: .id, tag: .tag})
Sort
Sort results:
.pid_graph.nodes | sort(.tag)
Combine Operations
Chain multiple operations:
.pid_graph.nodes | filter(.node_type == "pid_component") | map(.tag) | sort(.)
Common Queries
Get All Physical Components
{"query": ".pid_graph.nodes | filter(.node_type == \"pid_component\")"}
Get All Valves
{"query": ".pid_graph.nodes | filter(contains(.node_classification, \"valve\"))"}
Get All Pipe Segments (PNSG)
{"query": ".pid_graph.nodes | filter(.node_type == \"piping_network_segment\")"}
Get All Hierarchy Relationships
{"query": ".pid_graph.edges | filter(.edge_type == \"has_a\")"}
Get Metadata Only
{"query": ".pid_graph.metadata"}
Count Nodes by Type
{"query": ".pid_graph.nodes | filter(.node_type == \"pid_component\")"}
Then count the results in your application.
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer token for authentication. |
Content-Type | Yes | Must be application/json |
X-Schema-Version | No | Schema version. Defaults to latest. |
X-Change-Version | No | Graph version. Defaults to latest. |
Error Response
If the query syntax is invalid:
{
"error": "Query execution failed: Unknown function \"invalid_fn\"",
"query": ".nodes | invalid_fn()",
"hint": "Check JSONQuery syntax at https://jsonquerylang.org/"
}
See Also
- Common Queries - More query examples
- Understanding Nodes - Node types to filter by
- Understanding Edges - Edge types to filter by