Can you add AI to an existing business application?
Yes. An existing ASP.NET Core application can call an AI-assisted workflow through authenticated APIs while keeping business rules, SQL Server records and final approval inside the application. AI can suggest extracted values or exception categories, but the application should validate the results and require human approval before consequential actions.
You do not necessarily need to replace a working ERP, CRM, accounting tool or operations portal to test a useful AI feature. A small, well-bounded workflow can help a team review invoices or documents faster while maintaining traceability.
This article shows an illustrative invoice-processing scenario: an invoice enters an existing application, n8n orchestrates extraction and review, an AI model proposes structured fields, and SQL Server stores a pending review rather than posting a payment automatically.
Reference architecture: five accountable stages
Keep the boundaries explicit. ASP.NET Core owns authentication and user interaction. n8n coordinates integrations. The AI service proposes data, not permissions. SQL Server holds durable state, and a person makes the final decision.
For confidential documents, first agree on data retention, provider settings, redaction and regional processing requirements. Send only the fields needed for the task. In this illustration, the sample payload uses fictitious values.
1. Start from a controlled ASP.NET Core endpoint
ASP.NET Core should authorize the user, validate the invoice ID and amount, and enqueue a review request. An HTTP 202 response means queued for processing, not approved. For resilience, record an idempotency key and durable job state before forwarding work to n8n.
// Inside an authenticated ASP.NET Core endpoint or service.
// Register: builder.Services.AddHttpClient("workflow");
public record InvoiceReviewRequest(string InvoiceId, decimal Total, string Currency);
app.MapPost("/api/invoices/queue-review", async (
InvoiceReviewRequest input,
IHttpClientFactory clients,
IConfiguration configuration,
CancellationToken cancellationToken) =>
{
if (string.IsNullOrWhiteSpace(input.InvoiceId) || input.Total <= 0)
return Results.BadRequest(new { error = "Invalid invoice" });
var url = configuration["Workflow:WebhookUrl"]
?? throw new InvalidOperationException("Webhook URL missing");
var secret = configuration["Workflow:WebhookSecret"]
?? throw new InvalidOperationException("Webhook secret missing");
using var request = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = JsonContent.Create(new {
reviewId = Guid.NewGuid(),
invoiceId = input.InvoiceId,
total = input.Total,
currency = input.Currency
})
};
request.Headers.Add("X-Workflow-Secret", secret);
var client = clients.CreateClient("workflow");
using var response = await client.SendAsync(request, cancellationToken);
if (!response.IsSuccessStatusCode)
return Results.StatusCode(502); // Queueing failed: retry safely
return Results.Accepted(); // Accepted for processing, not approved
}).RequireAuthorization();This simplified sample assumes you have already configured authentication/authorization, HTTPS, secrets and a trusted n8n endpoint. In production, add authorization policies, retries with a durable outbox, structured logging and a per-request idempotency key.
2. Store proposals and decisions in SQL Server
Do not let a model directly update the accounting ledger. Save the proposal as Pending, record the reason it was flagged, and make the reviewer’s decision an explicit, authorized action.
CREATE TABLE dbo.InvoiceReview (
ReviewId uniqueidentifier NOT NULL PRIMARY KEY,
InvoiceId nvarchar(64) NOT NULL,
ProposedData nvarchar(max) NULL,
Status nvarchar(16) NOT NULL DEFAULT 'Pending',
ReviewedBy nvarchar(128) NULL,
CreatedUtc datetime2 NOT NULL DEFAULT sysutcdatetime(),
ReviewedUtc datetime2 NULL,
RowVer rowversion NOT NULL,
CONSTRAINT CK_InvoiceReview_Status
CHECK (Status IN ('Pending', 'Approved', 'Rejected'))
);
-- Add suitable indexes, tenant boundaries and authorization in production.
-- Use unique external event IDs to prevent duplicate processing.In a multi-tenant product, include organization identifiers and row-level access controls. A rowversion column can help detect concurrent updates when two reviewers open the same item.
3. Orchestrate the steps in n8n
A typical workflow can use these n8n nodes. The webhook can be protected with header authentication, and the production URL should be used only after the workflow is published.
- Webhook: receive the authenticated, minimal invoice event from ASP.NET Core.
- HTTP Request or application API: retrieve only the approved invoice fields; avoid passing credentials to model prompts.
- Model API call: request schema-constrained JSON for supplier, amount, currency, purchase-order match and review reasons.
- IF / validation: check schema, amount bounds, required fields, duplicates and deterministic business rules independently of the model.
- SQL Server / internal API: store the proposed result with
Status = Pendingand its correlation ID. - Notification: alert an authorized reviewer; the actual approval happens in your protected application UI, not through an untrusted AI answer.
Example output from the model
{
"invoiceId": "INV-DEMO-1042",
"supplierName": "Example Supplier",
"currency": "USD",
"amount": 1250.00,
"purchaseOrderMatched": false,
"reviewReasons": ["No matching purchase order"],
"suggestedAction": "Review"
}Use the model output as a proposal. If the order is missing, the amount differs, or a document looks suspicious, keep the item in manual review. Use structured output schemas where supported, then validate the returned data again on your server. See the model API reference.
4. Security and reliability checks before production
Automation becomes valuable when exceptions are visible and the system fails safely. For a real deployment, plan these controls before connecting the workflow to purchasing or finance systems.
- Secrets: keep model keys, n8n webhook credentials and database passwords in server-side secret storage—not in browser JavaScript or GitHub.
- Authentication: require application authorization, signed or authenticated callbacks and least-privilege service accounts.
- Prompt injection: treat document text and model replies as untrusted input; never allow extracted text to override permissions or execute actions.
- Traceability: connect each invoice event, model proposal, reviewer decision and downstream change to a correlation ID.
- Idempotency: ensure retries and repeated webhooks cannot duplicate invoices or purchase orders.
- Evaluation: measure field-level accuracy, false negatives, escalation rate, review time and per-document costs with representative test documents.
Keep a reviewer in the loop for payments, supplier onboarding, customer-facing commitments, regulated decisions, sensitive personal data and any irreversible change. An AI model’s confidence score is not a substitute for auditability or business validation.
Questions project owners ask before building
Can AI work with an existing ASP.NET MVC or ASP.NET Core system?
Often yes, using secure APIs or a narrowly scoped background service. First check the framework version, authentication model, database dependencies and available integration points. A phased integration is usually safer than rewriting the whole application just to add AI.
Does n8n replace ASP.NET Core?
No. n8n is useful for coordinating triggers, integrations and notifications. ASP.NET Core can remain the system of record for user permissions, complex business rules, secure application APIs and review screens.
Should an AI model approve invoices automatically?
Not by default. Extracted fields can be wrong, and invoices can contain misleading or malicious content. Begin with suggested fields and human approval, then automate only well-tested low-risk steps under explicit business rules.
What affects the cost of an AI integration project?
Scope depends on input document formats, integration access, data quality, volume, model usage, accuracy requirements, review screens, hosting and security. A short discovery and sample-data test provides more reliable estimates than a fixed promise without requirements.
Further reading and implementation references
These are authoritative product references for the concepts shown above. Exact implementation details depend on your framework and provider versions.