Dynamics 365 Custom API: Create a Reusable Server-Side Business Operation

A Dataverse Custom API defines a named operation in the platform. It can expose request and response parameters and be implemented by a plug-in, allowing clients to invoke domain logic without duplicating the rules in each caller.

When this pattern is useful

Design a Dataverse Custom API backed by a plug-in to expose reusable business logic to Power Automate, model-driven apps and integrations.

Implementation steps

  • Define the operation name, unique name, binding type and whether it is a function or action. Use a publisher prefix for custom schema names.
  • Add request parameters and response properties with suitable Dataverse types. Keep the contract small and stable.
  • Register a plug-in type as the Custom API’s main operation implementation and read inputs from InputParameters.
  • Return output values through OutputParameters and throw InvalidPluginExecutionException for actionable business failures.
  • Invoke the operation through the Dataverse Web API or a supported client and validate security privileges.

Example implementation

// Core pattern inside the Custom API plug-in
public void Execute(IServiceProvider serviceProvider)
{
    var context = (IPluginExecutionContext)serviceProvider
        .GetService(typeof(IPluginExecutionContext));

    var input = context.InputParameters.Contains("TargetCode")
        ? (string)context.InputParameters["TargetCode"]
        : throw new InvalidPluginExecutionException("TargetCode is required.");

    // Apply domain validation and business logic here.
    context.OutputParameters["ResultMessage"] = $"Processed {input}";
}

Common pitfalls

  • Do not treat a Custom API as a replacement for every CRUD Web API call.
  • Avoid changing parameter names or types after clients depend on the operation.
  • Validate who can execute the operation and whether it should be bound to an entity.

Validation checklist

Test missing inputs, valid and invalid business cases, caller privileges, and invocation from each intended client.

Conclusion

A reliable implementation starts with a clear contract, explicit failure handling and repeatable environment configuration. Test the operational edge cases—not only the happy path—before making this part of a production workload.