Deleting Records in the ServiceAPI from .Net

Background

Unfortunately deleting a Record (or other object type) is slightly different to other ServiceAPI requests.  This is both because most requests assume a response and also because the delete service is not explicitly built into the .Net client.

Two ways to delete

Each HPRM object has a Delete service which can be posted to via a URL following this pattern: /Record/{Id}/Delete.  Given that the .Net client classes do not have a facility to post to a specified URL you would need to write your own code to post to this URL.

The second way to delete is to post the deletion request to one of the built-in service endpoints.  This can be done like this:

trimClient.Post((new DeleteRecord() { Id = 1837.ToString(), DeleteContents = true });

Or this:

trimClient.Post(new DeleteMainObject() { TrimType = BaseObjectTypes.Record, Id = "1838" });

The catch

Not every version of the ServiceAPI enables the built-in service endpoints by default.  They can be switched on by adding PreDefinedRoutes to the serviceFeatures in the hptrim.config file.

<hptrim 
        poolSize="1000"
        serviceFeatures="Json,PreDefinedRoutes,Razor,Html" 
        ...
>