Sample data is great for any demo and testing of a feature in CRM instance. We can install and uninstall Sample Data from CRM by navigating to Settings->Data Management->Sample Data

We could also install and uninstall Sample Data using Web API and Organization Service through C# code.
Using the Web API
Install sample data using the InstallSampleData Action
POST [Organization URI]/api/data/v9.0/InstallSampleData HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Uninstall sample data using the UninstallSampleData Action
POST [Organization URI]/api/data/v9.0/UninstallSampleData HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Using the Organization Service
Install sample data using the InstallSampleDataRequest
var request = new InstallSampleDataRequest();
_orgService.Execute(request);
Uninstall sample data using the UninstallSampleDataRequest
var request = new UninstallSampleDataRequest();
_orgService.Execute(request);
Hope this helps!
One thought on “{Common Data Service} Install and Uninstall Sample Data programatically”