Resource Deleter
A package which deletes resources from the commercetools platform.
Examples of the resources are :
- carts
- categories
- channels
- customergroups
- customers
- customobjects
- discountcodes
- inventoryentries
- orders
- payments
- productdiscounts
- products
- producttypes
- reviews
- shippingmethods
- states
- taxcategories
- types
- zones
Configuration
The constructor accepts two arguments:
- A required object containing the following values:
apiConfig
(Object):AuthMiddleware
options for authentication on the commercetools platform. (Required. See here).accessToken
(String): [Access token] to be used to authenticate requests to API. Requires scope of [manage_products
,manage_customers
,manage_types
]. More info on how to get the access token here.resource
(String): [resource] that need to be deleted.predicate
(String): Query string specifying (where) predicate. More info on predicates here (Optional).
- An optional logger object having four functions (
info
,warn
,error
anddebug
).
Usage
npm install @commercetools/resource-deleter --global
CLI
Usage: resource-deleter [options]
Delete resource from the commercetools platform.
Options:
--help Show help text. [boolean]
--version Show version number. [boolean]
--output, -o Path to output file. [default: "stdout"]
--apiUrl The host URL of the HTTP API service.
[default: "https://api.europe-west1.gcp.commercetools.com"]
--authUrl The host URL of the OAuth API service.
[default: "https://auth.europe-west1.gcp.commercetools.com"]
--accessToken CTP client access token.
Required scopes: ['manage_products', 'manage_customers', 'manage_types'][string]
--projectKey, -p API project key. [required]
--resource, -r Resource that need to be deleted. [required]
--confirm, -c Confirm the resource to delete. [boolean]
[default: "false"]
--where, -w specify where predicate.
--logLevel Logging level: error, warn, info or debug.
[default: "info"]
--prettyLogs Pretty print logs to the terminal. [boolean]
--logFile Path to file where to save logs file.
[default: "resource-deleter.log"]
Then you can delete resource using the cli:
- Without predicate
resource-deleter -p my-project-key -r my-resource
- With predicate
resource-deleter -p my-project-key -r my-resource -w my-desired-key
Info on flags
- The
--output
flag specifies where to output the deleted resource. Several notes on this flag:- The default location for status report logging is the standard output.
- If no output path is specified, the deleted resource output will be logged to the standard output as a result, status reports will be logged to a
resource-deleter.log
file in the current directory.
- The
where
flag specifies an optional (where) query predicate to be included in the request. This predicate should be wrapped in single quotes ('single quoted predicate'). More info on predicates here.
JS
For more direct usage, it is possible to use this module directly:
import resourceDeleter from '@commercetools/resource-deleter'
const options = {
apiConfig: {
apiUrl: 'https://api.europe-west1.gcp.commercetools.com',
host: 'https://auth.europe-west1.gcp.commercetools.com',
project_key: 'my-project-key',
credentials: {
clientId: '*********',
clientSecret: '*********',
},
},
accessToken: '123456yuhgfdwegh675412wefb4rgb',
resource: 'my-resource',
predicate: 'key="my-desired-key"',
logger: {
error: console.error,
warn: console.warn,
info: console.log,
debug: console.debug,
},
}
const resourceDeleter = new ResourceDeleter(options)
resourceDeleter
.run()
.then(() => {
console.log('resource deleted')
})
.catch((error) => {
// handle error
})