← Back to Documentation

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/api

Authentication

API Key in request body

Send Statistics

POST/api/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

FieldTypeRequiredDescription
apiKeystringRequiredYour project API key
snapshotLabelstringRequired"before", "after", or "periodic"
collectedAtISO 8601OptionalWhen data was collected (defaults to now)
tablesarrayRequiredArray of table statistics (min 1)

Table Object

FieldTypeRequiredDescription
tableNamestringRequiredD365 table name (e.g., "BatchJobHistory")
recordCountintegerRequiredNumber of records in the table
dataSizeMBnumberOptionalData size in megabytes
indexSizeMBnumberOptionalIndex size in megabytes
totalSizeMBnumberOptionalTotal size (data + index) in MB
dataAgeMonthsintegerOptionalAge 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

400Invalid payload
{ "error": "Invalid payload", "details": [...] }
401Invalid API key
{ "error": "Invalid API key" }
403Project inactive
{ "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)

  1. Before cleanup: Send statistics with snapshotLabel: "before"
    → Creates a new cleanup session (status: PENDING)
  2. Perform cleanup: Delete old records, purge logs, etc.
  3. 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.

Detection criteria: At least 1,000 records and 10 MB decrease, or 1%+ reduction in both records and size.

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 dataAgeMonths to 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