Created
May 22, 2020 08:00
-
-
Save btastic/362ac1e5b0991f1b7bc19fca1aa1796e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reference commercetools.NET.SDK via nuget | |
using System; | |
using System.Threading.Tasks; | |
using commercetools.Categories; | |
using commercetools.Common; | |
using commercetools.ProductProjections; | |
using commercetools.ProductProjectionSearch; | |
using commercetools.Products; | |
using commercetools.Products.UpdateActions; | |
namespace ctdeleteallproducts | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
IClient client = new Client(new Configuration() | |
{ | |
OAuthUrl = "https://auth.sphere.io/oauth/token", | |
ApiUrl = "https://api.sphere.io", | |
ClientID = "client_id_here", | |
ClientSecret = "client_secret_here", | |
ProjectKey = "project_key_here" | |
}); | |
var categoriesResponse = await client.Categories().QueryCategoriesAsync(limit: 500); | |
var categories = categoriesResponse.Result; | |
foreach (var category in categories.Results) | |
{ | |
await client.Categories().DeleteCategoryAsync(category); | |
} | |
Response<ProductProjectionQueryResult> result = await client.ProductProjectionSearch() | |
.SearchProductProjectionsAsync(); | |
var productsResponse = await client.Products().QueryProductsAsync(limit: 500); | |
if(!productsResponse.Success) | |
{ | |
return; | |
} | |
var products = productsResponse.Result; | |
foreach (var product in products.Results) | |
{ | |
var unpublishResult = await client.Products().UpdateProductAsync(product, new UnpublishAction()); | |
var unpublishedProduct = await client.Products().GetProductByIdAsync(product.Id); | |
var ya = await client.Products().DeleteProductAsync(unpublishedProduct.Result); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment