![]() |
commercetools.Sdk
The commercetools platform, import-api and C# sdks generated from our api reference.
|
The SDK V2 has some features which is not exists in V1 like:
Package | V2 | V1 |
---|---|---|
HTTP API | dotnet add package commercetools.Sdk.Api | dotnet add package commercetools.Sdk.All |
Import API | dotnet add package commercetools.Sdk.ImportApi | |
Machine Learning API | dotnet add package commercetools.Sdk.MLApi | |
Change History API | dotnet add package commercetools.Sdk.HistoryApi |
After packages installation, you have to configure services using Dependency Injection Setup in the application Startup.cs
Package | V2 | V1 |
---|---|---|
HTTP API | services.UseCommercetoolsApi(this.configuration, "Client"); | services.UseCommercetools( |
this.configuration,"Client"); | ||
Import API | services.UseCommercetoolsImportApi(this.configuration, "ImportClient"); | |
Machine Learning API | services.UseCommercetoolsMLApi(this.configuration, "MLClient"); | |
Change History API | services.UseCommercetoolsHistoryApi(this.configuration, "HistoryClient"); |
Request | V2 | V1 |
---|---|---|
Create | var category = await projectApiRoot .Categories() .Post(categoryDraft) .ExecuteAsync(); | var category = await client .Builder() .Categories() .Create(categoryDraft) .ExecuteAsync(); |
Get By Id | var queriedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Get() .ExecuteAsync(); | var queriedCategory = await client .Builder() .Categories() .GetById(category.Id) .ExecuteAsync(); |
Get By Key | var queriedCategory = await projectApiRoot .Categories() .WithKey(category.Key) .Get() .ExecuteAsync(); | var queriedCategory = await client .Builder() .Categories() .GetByKey(category.Key) .ExecuteAsync(); |
Query | var response = await projectApiRoot .Categories() .Get() .WithWhere($"key = \"{category.Key}\"") .ExecuteAsync(); | var response = await client .Builder() .Categories() .Query() .Where(c => c.Key == category.Key.valueOf()) .ExecuteAsync(); |
Delete By Id | var deletedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Delete() .WithVersion(category.version) .ExecuteAsync(); | var category = await client .Builder() .Categories() .DeleteById(category) .ExecuteAsync(); |
Delete By Key | var deletedCategory = await projectApiRoot .Categories() .WithKey(category.Key) .Delete() .WithVersion(category.version) .ExecuteAsync(); | var category = await client .Builder() .Categories() .DeleteByKey(category.Key, category.Version) .ExecuteAsync(); |
Update | var updatedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Post(categoryUpdate) .ExecuteAsync(); | var updatedCategory = await client .Builder() .Categories() .UpdateById(category) .AddAction(action) .ExecuteAsync(); |