API Reference
Technical documentation for integrating D365 F&O with SIMS TSize.
Overview
SIMS TSize provides a REST API for sending table size statistics from your Dynamics 365 Finance & Operations environment.
Base URL
https://your-domain.com/apiAuthentication
API Key in request bodySend Statistics
Send table size statistics from your D365 system.
Request Body
{
"apiKey": "sims_proj_xxxxxxxxxxxxx",
"snapshotLabel": "before" | "after" | "periodic",
"collectedAt": "2024-01-15T10:30:00Z", // optional
"tables": [
{
"tableName": "BatchJobHistory",
"recordCount": 5000000,
"dataSizeMB": 1200.5,
"indexSizeMB": 450.2,
"totalSizeMB": 1650.7,
"dataAgeMonths": 24
}
]
}Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| apiKey | string | Required | Your project API key |
| snapshotLabel | string | Required | "before", "after", or "periodic" |
| collectedAt | ISO 8601 | Optional | When data was collected (defaults to now) |
| tables | array | Required | Array of table statistics (min 1) |
Table Object
| Field | Type | Required | Description |
|---|---|---|---|
| tableName | string | Required | D365 table name (e.g., "BatchJobHistory") |
| recordCount | integer | Required | Number of records in the table |
| dataSizeMB | number | Optional | Data size in megabytes |
| indexSizeMB | number | Optional | Index size in megabytes |
| totalSizeMB | number | Optional | Total size (data + index) in MB |
| dataAgeMonths | integer | Optional | Age of oldest data in months |
Success Response (200)
{
"success": true,
"message": "Received 5 table statistics",
"recordsCreated": 5,
"snapshotLabel": "before",
"collectedAt": "2024-01-15T10:30:00.000Z",
"cleanupSession": {
"id": "abc123xyz",
"status": "PENDING"
}
}When snapshotLabel is "before", a new cleanup session is created. When "after", the session is completed and cleanup statistics are calculated automatically.
Error Responses
{ "error": "Invalid payload", "details": [...] }{ "error": "Invalid API key" }{ "error": "Project is inactive" }X++ Integration Example
Example X++ code to collect and send table statistics from D365 F&O:
public class SIMSTSizeStatisticsCollector
{
private const str ApiEndpoint = "https://your-domain.com/api/statistics";
private const str ApiKey = "sims_proj_xxxxxxxxxxxxx";
public static void collectAndSend()
{
container tables = conNull();
// Query table sizes from sys.dm_db_partition_stats
SqlDataDictionary sqlDict = new SqlDataDictionary();
// Add tables to collect
tables += SIMSTSizeStatisticsCollector::getTableStats("BatchJobHistory");
tables += SIMSTSizeStatisticsCollector::getTableStats("SysOutgoingEmailTable");
tables += SIMSTSizeStatisticsCollector::getTableStats("DocuRef");
// Build JSON payload
str jsonPayload = SIMSTSizeStatisticsCollector::buildJson(tables);
// Send to API
SIMSTSizeStatisticsCollector::sendToApi(jsonPayload);
}
private static container getTableStats(TableName _tableName)
{
// Implementation depends on your D365 version
// Query sys.dm_db_partition_stats for size info
return [_tableName, recordCount, dataSizeMB, indexSizeMB];
}
private static void sendToApi(str _jsonPayload)
{
System.Net.HttpWebRequest request;
System.Net.HttpWebResponse response;
System.IO.StreamWriter writer;
request = System.Net.WebRequest::Create(ApiEndpoint) as System.Net.HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/json";
writer = new System.IO.StreamWriter(request.GetRequestStream());
writer.Write(_jsonPayload);
writer.Close();
response = request.GetResponse() as System.Net.HttpWebResponse;
if (response.StatusCode == System.Net.HttpStatusCode::OK)
{
info("Statistics sent successfully");
}
}
}This is a simplified example. Adapt it to your D365 version and security requirements.
cURL Example
curl -X POST https://your-domain.com/api/statistics \
-H "Content-Type: application/json" \
-d '{
"apiKey": "sims_proj_xxxxxxxxxxxxx",
"snapshotLabel": "before",
"tables": [
{
"tableName": "BatchJobHistory",
"recordCount": 5000000,
"dataSizeMB": 1200.5,
"indexSizeMB": 450.2,
"totalSizeMB": 1650.7
}
]
}'Cleanup Session Workflow
Choose how to track cleanup sessions. Configure your mode in Client Dashboard → Settings.
Manual Mode(Default)
- Before cleanup: Send statistics with
snapshotLabel: "before"
→ Creates a new cleanup session (status: PENDING) - Perform cleanup: Delete old records, purge logs, etc.
- After cleanup: Send statistics with
snapshotLabel: "after"
→ Completes the session, calculates records/size cleaned
Auto Mode(Automatic Detection)
Send statistics with snapshotLabel: "periodic"on every update (e.g., daily or weekly). The system will automatically detect significant decreases and record cleanup sessions.
Tip: View your cleanup impact in the Client Dashboard → "Your Cleanup Impact" section. Share your results with the community by enabling "Share anonymous statistics" in Settings.
Best Practices
- Send
snapshotLabel: "before"before cleanup - Send
snapshotLabel: "after"after cleanup to show improvements - Use
snapshotLabel: "periodic"for regular monitoring - Include
dataAgeMonthsto help engineers understand data retention - Keep your API key secure — don't commit it to version control
- Regenerate your API key if you suspect it's compromised