Export Service Map via External API¶
This document explains how to use the TrueWatch External API to retrieve service nodes and call relationships, and to aggregate Service Map data within a specified site by querying workspace by workspace.
The API returns JSON. Generating CSV, Excel, or an application dependency manifest requires the caller to organize the returned results.
Applicable Scope¶
- Query the APM Service Map collected within a specified time range to sort out call relationships between services.
- For a single workspace, use the Service Map API; for all workspaces in a site, use the "paginate the workspace list → query the topology of each workspace → aggregate the results" flow.
- Export results are affected by collection completeness, data retention time, and deployment version. They do not represent all historical dependencies or call relationships that were not collected.
- This document specifies one
workspaceUUIDper request. The console's cross-workspace selector works differently from this flow; do not combine multiple UUIDs or*intoworkspaceUUID.
If you need to analyze call relationships between different workspaces, confirm that the corresponding collection and cross-workspace topology capabilities are already in place at the site. See Cross-Workspace Configuration for APM Service Map. Aggregating workspace by workspace will not add cross-workspace call edges that do not exist in the source data.
Prerequisites¶
- Confirm the External API Endpoint of the current site. It is usually
https://external-api.truewatch.com. Follow the actual deployment address; do not use the console front or the OpenAPI Endpoint as a substitute. - Prepare the AK/SK for the External API and generate the request headers according to API Signature Authentication. Do not replace the signature with the workspace OpenAPI
DF-API-KEY. - On versions that support External read-only accounts, a read-only account can be used to call the two query APIs in this document. Accounts are configured by the site administrator.
- Fix a pair of
startandendvalues, both of which are millisecond timestamps, andstart < end. All workspaces use the same time range.X-Df-Timestampin the signature header is the second timestamp when each request is made. - First select one workspace and verify the response using the same time range and filter conditions as the console, then start the batch export. Support for parameters such as the newly added grouping in the Deployment Plan depends on the version deployed at your site.
Step 1: Paginate the Workspace List¶
Call the List Workspaces API:
pageIndex starts at 1; pageSize has a maximum of 100. Do not pass search when exporting all workspaces in the site.
Read the following from the response:
| Field | Purpose |
|---|---|
content.data[].uuid |
The workspaceUUID for subsequent topology requests |
content.data[].name |
Adds the name of the queried workspace to the exported data |
content.pageInfo.totalCount |
Total number of matching workspaces, used to determine whether to continue paginating |
Increment pageIndex by 1 each time until all paginated results are traversed. Deduplicate by UUID and save the list of workspaces actually queried this run. If an empty page is returned before the total count is reached, record the anomaly and re-check; do not simply declare that all workspaces were exported successfully. Paginated results may also change if workspaces are created or deleted during the export.
Step 2: Retrieve the Service Map of Each Workspace¶
Call the Service Map API:
The example time range is from 2026-09-15 08:00 to 2026-09-16 08:00 Beijing time. Replace it with a range that you actually need and that is still within the data retention period.
The following request shows the signature headers that must be included. It cannot be executed directly with placeholders:
curl '<Endpoint>/api/v1/tracing/service_map_v2?workspaceUUID=wksp_example&start=1789430400000&end=1789516800000' \
-H 'X-Df-Access-Key: <AK>' \
-H 'X-Df-SVersion: v20240417' \
-H 'X-Df-Timestamp: <current second timestamp>' \
-H 'X-Df-Nonce: <random nonce for this request>' \
-H 'X-Df-Signature: <signature computed from the final request path>'
A new nonce, timestamp, and signature must be regenerated for each request. The signature uses the original path and query string of the final request sent; after adding parameters such as groupBy or applying URL encoding, re-sign using the final path.
Selecting the Query Scope¶
| Goal | Parameter Settings |
|---|---|
| Get the complete topology of a workspace for the selected time range | Pass only workspaceUUID, start, and end; do not pass centralService, search, or restrictive filters |
| Get the topology of a specified central service | Add centralService, for example centralService=demo-web |
| Distinguish environments and versions | Add groupBy=env,version on versions that support this parameter |
| Distinguish projects or K8s clusters | Set groupBy=project, groupBy=cluster_name_k8s, or a combination as needed |
groupBy affects node identity, so all workspaces should use the same grouping criteria. When a central service is specified and grouping is enabled, fields such as centralWorkspaceUUID and centralEnv can be used to further locate the central node. See the API parameter documentation for details.
The console's single-service "upstream/downstream" view includes a central service restriction and cannot be directly treated as the topology of the entire workspace. When comparing the page with the API, align the time, workspace, grouping, and filter conditions at the same time. Display attributes such as graph layout and node colors are not business relationships that need to be exported.
For export, read content.services and content.maps directly. Do not rely on serviceMapList=true to generate additional lists or download files.
Step 3: Save Nodes, Call Edges, and Execution Results¶
For each request, first check the HTTP status and the code, success, and errorCode fields in the response. On success, save the complete JSON along with the workspace UUID, time range, and grouping parameters of this query.
| Field | Description |
|---|---|
content.services |
List of service nodes; keep the node name, workspace identity, node ID (if present), and data |
content.maps |
Directed call edges; source is the caller and target is the callee |
maps[].source_workspace_uuid / target_workspace_uuid |
The workspaces to which the two ends of an edge belong (preserve them if returned) |
maps[].source_id / target_id |
The node IDs of the two ends of an edge (preserve them if returned); can be used to distinguish nodes with the same name |
maps[].avg_per_second, error_count, error_rate, p99 |
Statistical fields that may be returned for call edges; subject to what the actual version returns |
See Service Map Response Example for a redacted excerpt of a response verified in a test environment. The example keeps the fields and statistical values of the selected nodes and call edges and cannot replace response verification at your site.
It is recommended to output two types of files:
- Raw JSON: Save separately by queried workspace, keeping nodes, edges, statistical values, and the response
traceIdfor later review. - Call Relationship Table: Each row records one directed call relationship, including at least the queried workspace, source workspace, source service, target workspace, target service, start time, and end time. Add node IDs and grouping dimensions based on the actual response.
Aggregation rules:
A → BandB → Aare two different relationships.- Services with the same name in different workspaces must not be merged by name alone. Prefer "workspace identity + node ID"; when the ID is missing, use "workspace identity + service name + selected grouping dimensions". If the workspace identity cannot be confirmed, mark the entry as pending verification and do not guess the workspace of the other end of an edge based on the queried workspace.
- The same call edge may appear in query results from multiple workspaces. The relationship table can be deduplicated by the directed edges formed by the node identities above, while keeping the originating query workspace; the raw JSON is not deduplicated.
- Do not directly add up the request counts of duplicate edges, and do not directly average request rates, error rates, or P99. If global statistics are needed, define a separate aggregation approach.
- Save
servicesandmapsseparately. Extracting nodes only from call edges may miss services without call edges. - Missing fields must not be treated as
0. In particular, distinguish between "not returned" and "returned as zero" for statistical fields.
Batch Execution Flow¶
The following is pseudocode for the flow. Signing client implementations can reuse the Python example in API Signature Authentication.
Fix start, end, and groupBy
Paginate through workspace/list, save and deduplicate by uuid to get the workspace list
If the workspace list fails to be read: stop and mark this export as incomplete
For each workspace in the list, execute serially:
Regenerate the signature and query service_map_v2
If the HTTP or business status fails:
Record the failed workspace, error code, and traceId, and continue with other workspaces
If successful but the services/maps structure is abnormal:
Save the raw response, mark the structure as abnormal, and do not treat it as an empty topology
If successful and the structure is normal:
Save the raw JSON
If both services and maps are empty, record "no topology data for this time range"
Otherwise, organize the call relationship table by node identity
Output the total number of workspaces, number of successes, number with no data, number of failures, and the list of failed workspaces
If there are failures or structural anomalies: mark the results as partially complete
Retry the failed workspaces within the same time range, then update the aggregated results
It is recommended to run queries serially first and set a reasonable request timeout. When there are many workspaces, control concurrency based on the load at your site. The Service Map API does not expose pagination parameters like pageIndex/pageSize; do not apply the workspace list pagination approach to obtain more call edges. When the data volume is large, check the query limits and response completeness at your site.
Validation and Troubleshooting¶
| Symptom | Check Method |
|---|---|
| Signature failure | Check the Endpoint, AK/SK, v20240417, system time, and whether the signed path is consistent with the final URL encoding and parameter order |
| Only relationships near one service are exported | Check whether the centralService, search, or filter conditions in the page request were copied |
| Inconsistent with the number of services on the page | Align the workspace, time, grouping, filters, and the upstream/downstream vs. complete topology view; the page also processes nodes and edges for display |
| No cross-workspace call edges | Check collection, the version at your site, and the cross-workspace topology configuration; do not infer complete cross-workspace relationships from per-workspace aggregation alone |
| Services with the same name are merged | Check whether workspace identity, node ID, and groupBy dimensions are included in deduplication |
| Empty results | First confirm the request is successful and the structure is normal, then check the time range, retention period, and whether APM data exists in that workspace |
| Some workspace requests fail | Keep the failure list and traceId, retry, and then confirm whether the export is complete |
Before releasing to a customer environment, it is recommended to verify at least: a workspace with call relationships, a workspace without topology data, workspace list pagination, recording of failed workspaces, and differentiation of services with the same name across different workspaces.