> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # CreateTask # Package: operations # Namespace: TaskService # Method link: https://dev.wix.com/docs/api-reference/business-solutions/cms/operations/background-tasks/create-task.md ## Permission Scopes: Write Data Items: SCOPE.DC-DATA.WRITE Write Data Items: SCOPE.DC-DATA.WRITE Write Data Items: SCOPE.DC-DATA.WRITE Write Data Items: SCOPE.DC-DATA.WRITE Write Data Items: SCOPE.DC-DATA.WRITE ## Introduction Creates and runs a new background task. --- ## REST API ### Schema ``` Method: createTask Description: Creates and runs a new background task. URL: https://www.wixapis.com/v1 Method: POST # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: task, task.type, task.deleteByQueryOptions.dataCollectionId Method parameters: param name: task | type: Task | description: Background task job that processes data items in bulk. | required: true - ONE-OF: - required: true - name: deleteByQueryOptions | type: DeleteByQueryOptions | description: Options for tasks of the type `DELETE_BY_QUERY`. - name: dataCollectionId | type: string | description: GUID of the collection from which to delete the items that match the filter. | required: true - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing) from which to delete item. Default: `LIVE`. - enum: - SANDBOX: Collection [sandbox environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections). - SANDBOX_PREFERRED: If the [collection's sandbox environment is enabled](https://support.wix.com/en/article/cms-accessing-and-syncing-your-sandbox-and-live-collections#enabling-sandbox-collections), run the task in the collection's sandbox environment. If not, run the task in the collection's live environment. - LIVE: Collection [live environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#live-collections). - name: filter | type: object | description: Query filter. If not specified, all items are deleted. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: appOptions | type: object | description: Additional options specific to the [Wix app collection](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) you are querying. Learn more about [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md). - name: publishPluginOptions | type: PublishPluginOptions | description: Options for the [Publish plugin](https://support.wix.com/en/article/cms-controlling-live-site-item-visibility-from-your-collection). This plugin allows items in a [data collection](https://dev.wix.com/docs/rest/business-solutions/cms/data-collections/data-collection-object.md) to be marked as draft or published. Published items are visible to site visitors, while draft items are not. - name: includeDraftItems | type: boolean | description: Whether to include draft items. When `true`, both published and draft items are affected. Default: `false`. - name: copyFieldDataOptions | type: CopyFieldDataOptions | description: Options for tasks of the type `COPY_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to copy and write item field data. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to copy and write field data. Default: `LIVE`. - name: sourceFieldKey | type: string | description: GUID of the field to copy data from. - name: targetFieldKey | type: string | description: GUID of the field to copy data to. - name: editFieldDataOptions | type: EditFieldDataOptions | description: Options for tasks of the type `EDIT_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to edit the specified field. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to edit the specified field. Default: `LIVE`. - name: filter | type: object | description: Query filter. Only items that match the filter are edited. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: fieldKey | type: string | description: GUID of the field to update. - name: operations | type: Operations | description: Operations to perform on the specified field. - name: addItems | type: array | description: Add elements to a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - ONE-OF: - name: nullValue | type: | description: - name: numberValue | type: number | description: - name: stringValue | type: string | description: - name: boolValue | type: boolean | description: - name: structValue | type: object | description: - name: listValue | type: ListValue | description: - name: values | type: array | description: - name: removeItems | type: array | description: Remove elements from a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: replaceItems | type: array | description: In a field of type Array, replace all matching elements. In a field of another type, replace all matching values. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: from | type: Value | description: Value or array element to replace. - name: to | type: Value | description: Value or array element to replace with. - name: removeDuplicates | type: boolean | description: In a field of type Array, remove duplicate elements. Default: `false`. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: updatePublishStatusOptions | type: UpdatePublishStatusOptions | description: Options for tasks of the type `UPDATE_PUBLISH_STATUS`. - ONE-OF: - name: scheduleDraftStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_DRAFT_STATUS` operation, options for scheduling the status update to `DRAFT`. - name: date | type: string | description: When to update the item's publish status. - name: schedulePublishedStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_PUBLISHED_STATUS` operation, options for scheduling the status update to `PUBLISHED`. - name: dataCollectionId | type: string | description: GUID of the collection whose items' publish status is to be updated. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to update the publish status of the items. Default: `LIVE`. - name: filter | type: object | description: Query filter. If not specified, the publish status of all items is updated. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: operation | type: Operation | description: Publish status update operation. - enum: - SET_PUBLISHED_STATUS: Update the publish status of all items that match the filter to `PUBLISHED`. - SET_DRAFT_STATUS: Update the publish status of all items that match the filter to `DRAFT`. - SCHEDULE_PUBLISHED_STATUS: Schedule when to update the publish status of all items that match the filter to `PUBLISHED`. - SCHEDULE_DRAFT_STATUS: Schedule when to update the publish status of all items that match the filter to `DRAFT`. - CANCEL_SCHEDULING: Cancel all scheduled status updates. - name: type | type: Type | description: Task type. | required: true - enum: - DELETE_BY_QUERY: Deletes all items that match the specified filter. - COPY_FIELD_DATA: Copies data from one field to another for all items in the collection. - EDIT_FIELD_DATA: Updates field data for items that match the specified filter. - UPDATE_PUBLISH_STATUS: In collections that have the Publish plugin, updates the publish status of items that match the specified filter. Return type: CreateTaskResponse - name: task | type: Task | description: Created task. - ONE-OF: - name: deleteByQueryOptions | type: DeleteByQueryOptions | description: Options for tasks of the type `DELETE_BY_QUERY`. - name: dataCollectionId | type: string | description: GUID of the collection from which to delete the items that match the filter. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing) from which to delete item. Default: `LIVE`. - enum: - SANDBOX: Collection [sandbox environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections). - SANDBOX_PREFERRED: If the [collection's sandbox environment is enabled](https://support.wix.com/en/article/cms-accessing-and-syncing-your-sandbox-and-live-collections#enabling-sandbox-collections), run the task in the collection's sandbox environment. If not, run the task in the collection's live environment. - LIVE: Collection [live environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#live-collections). - name: filter | type: object | description: Query filter. If not specified, all items are deleted. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: appOptions | type: object | description: Additional options specific to the [Wix app collection](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) you are querying. Learn more about [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md). - name: publishPluginOptions | type: PublishPluginOptions | description: Options for the [Publish plugin](https://support.wix.com/en/article/cms-controlling-live-site-item-visibility-from-your-collection). This plugin allows items in a [data collection](https://dev.wix.com/docs/rest/business-solutions/cms/data-collections/data-collection-object.md) to be marked as draft or published. Published items are visible to site visitors, while draft items are not. - name: includeDraftItems | type: boolean | description: Whether to include draft items. When `true`, both published and draft items are affected. Default: `false`. - name: copyFieldDataOptions | type: CopyFieldDataOptions | description: Options for tasks of the type `COPY_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to copy and write item field data. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to copy and write field data. Default: `LIVE`. - name: sourceFieldKey | type: string | description: GUID of the field to copy data from. - name: targetFieldKey | type: string | description: GUID of the field to copy data to. - name: editFieldDataOptions | type: EditFieldDataOptions | description: Options for tasks of the type `EDIT_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to edit the specified field. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to edit the specified field. Default: `LIVE`. - name: filter | type: object | description: Query filter. Only items that match the filter are edited. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: fieldKey | type: string | description: GUID of the field to update. - name: operations | type: Operations | description: Operations to perform on the specified field. - name: addItems | type: array | description: Add elements to a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - ONE-OF: - name: nullValue | type: | description: - name: numberValue | type: number | description: - name: stringValue | type: string | description: - name: boolValue | type: boolean | description: - name: structValue | type: object | description: - name: listValue | type: ListValue | description: - name: values | type: array | description: - name: removeItems | type: array | description: Remove elements from a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: replaceItems | type: array | description: In a field of type Array, replace all matching elements. In a field of another type, replace all matching values. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: from | type: Value | description: Value or array element to replace. - name: to | type: Value | description: Value or array element to replace with. - name: removeDuplicates | type: boolean | description: In a field of type Array, remove duplicate elements. Default: `false`. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: updatePublishStatusOptions | type: UpdatePublishStatusOptions | description: Options for tasks of the type `UPDATE_PUBLISH_STATUS`. - ONE-OF: - name: scheduleDraftStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_DRAFT_STATUS` operation, options for scheduling the status update to `DRAFT`. - name: date | type: string | description: When to update the item's publish status. - name: schedulePublishedStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_PUBLISHED_STATUS` operation, options for scheduling the status update to `PUBLISHED`. - name: dataCollectionId | type: string | description: GUID of the collection whose items' publish status is to be updated. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to update the publish status of the items. Default: `LIVE`. - name: filter | type: object | description: Query filter. If not specified, the publish status of all items is updated. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: operation | type: Operation | description: Publish status update operation. - enum: - SET_PUBLISHED_STATUS: Update the publish status of all items that match the filter to `PUBLISHED`. - SET_DRAFT_STATUS: Update the publish status of all items that match the filter to `DRAFT`. - SCHEDULE_PUBLISHED_STATUS: Schedule when to update the publish status of all items that match the filter to `PUBLISHED`. - SCHEDULE_DRAFT_STATUS: Schedule when to update the publish status of all items that match the filter to `DRAFT`. - CANCEL_SCHEDULING: Cancel all scheduled status updates. - name: id | type: string | description: Task GUID. - name: type | type: Type | description: Task type. - enum: - DELETE_BY_QUERY: Deletes all items that match the specified filter. - COPY_FIELD_DATA: Copies data from one field to another for all items in the collection. - EDIT_FIELD_DATA: Updates field data for items that match the specified filter. - UPDATE_PUBLISH_STATUS: In collections that have the Publish plugin, updates the publish status of items that match the specified filter. - name: status | type: Status | description: Task status. - enum: - NEW: Task was created but has not started. - RUNNING: Task is currently running. - COMPLETED: Task has completed. Partial errors are listed in `failures`. - FAILED: Task has failed. Tasks can fail due to errors or because they were cancelled. Failures are listed in `failures`. Cancelled tasks have a failure `code` value of `CANCELLED`, and no associated failure `data`. - name: startedAt | type: string | description: Task start time. Empty if the task status is `NEW`. - name: finishedAt | type: string | description: Task finish time. Empty until the task status updates to `COMPLETED` or `FAILED`. - name: itemsFailed | type: integer | description: Number of items whose processing failed. - name: failures | type: array | description: List of errors generated during the task. Learn more about [Wix Data error codes](https://dev.wix.com/docs/sdk/backend-modules/data/wix-data-error-codes.md). - name: code | type: string | description: Error code. - name: description | type: string | description: Description of the error. - name: data | type: object | description: Data related to the error. - name: estimatedItemCount | type: integer | description: Estimated number of items affected by the task. - name: itemsSucceeded | type: integer | description: Number of items successfully processed so far. ``` ### Examples ### Create Update Publish Status task ```curl curl -X POST https://wixapis.com/autocms/v1/tasks \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{ "task": { "type": "UPDATE_PUBLISH_STATUS", "updatePublishStatusOptions": { "dataCollectionId": "Items", "environment": "LIVE", "filter": { "holidays": { "$in": ["Halloween"] } }, "operation": "SCHEDULE_PUBLISHED_STATUS", "schedulePublishedStatusOptions": { "date": "2025-01-01T10:00:00Z" } } } }' ``` ### Create Delete By Query task ```curl curl -X POST https://wixapis.com/autocms/v1/tasks \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{ "task": { "type": "DELETE_BY_QUERY", "deleteByQueryOptions": { "dataCollectionId": "Items", "environment": "LIVE", "filter": { "holidays": { "$in": ["Halloween"] } }, } } }' ``` ### Create Edit Field Data task ```curl curl -X POST https://wixapis.com/autocms/v1/tasks \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{ "task": { "type": "EDIT_FIELD_DATA", "editFieldDataOptions": { "dataCollectionId": "Items", "environment": "LIVE", "filter": { "holidays": { "$in": ["Halloween"] } }, "fieldKey": "tags", "operations": { "addItems": ["sale"], "removeItems": ["outdated"], "replaceItems": [{ "from": "Goob", "to": "Good" }], "removeDuplicates": true } } } }' ``` ### Create Copy Field Data task ```curl curl -X POST https://wixapis.com/autocms/v1/tasks \ -H 'Authorization: ' \ -H 'Content-Type: application/json' \ -d '{ "task": { "type": "COPY_FIELD_DATA", "copyFieldDataOptions": { "dataCollectionId": "Items", "environment": "LIVE", "sourceFieldKey": "fullName", "targetFieldKey": "fullNameCopy" } } }' ``` --- ## JavaScript SDK ### Schema ``` Method: wixClientAdmin.operations.TaskService.createTask(task) Description: Creates and runs a new background task. # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present. Required parameters: task, task.type, task.deleteByQueryOptions.dataCollectionId, task.updatePublishStatusOptions.dataCollectionId, task.updatePublishStatusOptions.operation, task.copyFieldDataOptions.dataCollectionId, task.copyFieldDataOptions.sourceFieldKey, task.copyFieldDataOptions.targetFieldKey, task.editFieldDataOptions.dataCollectionId, task.editFieldDataOptions.fieldKey Method parameters: param name: task | type: Task | description: Background task job that processes data items in bulk. | required: true - ONE-OF: - required: true - name: deleteByQueryOptions | type: DeleteByQueryOptions | description: Options for tasks of the type `DELETE_BY_QUERY`. - name: dataCollectionId | type: string | description: GUID of the collection from which to delete the items that match the filter. | required: true - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing) from which to delete item. Default: `LIVE`. - enum: - SANDBOX: Collection [sandbox environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections). - SANDBOX_PREFERRED: If the [collection's sandbox environment is enabled](https://support.wix.com/en/article/cms-accessing-and-syncing-your-sandbox-and-live-collections#enabling-sandbox-collections), run the task in the collection's sandbox environment. If not, run the task in the collection's live environment. - LIVE: Collection [live environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#live-collections). - name: filter | type: object | description: Query filter. If not specified, all items are deleted. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: appOptions | type: object | description: Additional options specific to the [Wix app collection](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) you are querying. Learn more about [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md). - name: publishPluginOptions | type: PublishPluginOptions | description: Options for the [Publish plugin](https://support.wix.com/en/article/cms-controlling-live-site-item-visibility-from-your-collection). This plugin allows items in a [data collection](https://dev.wix.com/docs/rest/business-solutions/cms/data-collections/data-collection-object.md) to be marked as draft or published. Published items are visible to site visitors, while draft items are not. - name: includeDraftItems | type: boolean | description: Whether to include draft items. When `true`, both published and draft items are affected. Default: `false`. - name: copyFieldDataOptions | type: CopyFieldDataOptions | description: Options for tasks of the type `COPY_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to copy and write item field data. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to copy and write field data. Default: `LIVE`. - name: sourceFieldKey | type: string | description: GUID of the field to copy data from. - name: targetFieldKey | type: string | description: GUID of the field to copy data to. - name: editFieldDataOptions | type: EditFieldDataOptions | description: Options for tasks of the type `EDIT_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to edit the specified field. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to edit the specified field. Default: `LIVE`. - name: filter | type: object | description: Query filter. Only items that match the filter are edited. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: fieldKey | type: string | description: GUID of the field to update. - name: operations | type: Operations | description: Operations to perform on the specified field. - name: addItems | type: array | description: Add elements to a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - ONE-OF: - name: nullValue | type: | description: - name: numberValue | type: number | description: - name: stringValue | type: string | description: - name: boolValue | type: boolean | description: - name: structValue | type: object | description: - name: listValue | type: ListValue | description: - name: values | type: array | description: - name: removeItems | type: array | description: Remove elements from a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: replaceItems | type: array | description: In a field of type Array, replace all matching elements. In a field of another type, replace all matching values. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: from | type: Value | description: Value or array element to replace. - name: to | type: Value | description: Value or array element to replace with. - name: removeDuplicates | type: boolean | description: In a field of type Array, remove duplicate elements. Default: `false`. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: updatePublishStatusOptions | type: UpdatePublishStatusOptions | description: Options for tasks of the type `UPDATE_PUBLISH_STATUS`. - ONE-OF: - name: scheduleDraftStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_DRAFT_STATUS` operation, options for scheduling the status update to `DRAFT`. - name: date | type: Date | description: When to update the item's publish status. - name: schedulePublishedStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_PUBLISHED_STATUS` operation, options for scheduling the status update to `PUBLISHED`. - name: dataCollectionId | type: string | description: GUID of the collection whose items' publish status is to be updated. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to update the publish status of the items. Default: `LIVE`. - name: filter | type: object | description: Query filter. If not specified, the publish status of all items is updated. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: operation | type: Operation | description: Publish status update operation. - enum: - SET_PUBLISHED_STATUS: Update the publish status of all items that match the filter to `PUBLISHED`. - SET_DRAFT_STATUS: Update the publish status of all items that match the filter to `DRAFT`. - SCHEDULE_PUBLISHED_STATUS: Schedule when to update the publish status of all items that match the filter to `PUBLISHED`. - SCHEDULE_DRAFT_STATUS: Schedule when to update the publish status of all items that match the filter to `DRAFT`. - CANCEL_SCHEDULING: Cancel all scheduled status updates. - name: type | type: Type | description: Task type. | required: true - enum: - DELETE_BY_QUERY: Deletes all items that match the specified filter. - COPY_FIELD_DATA: Copies data from one field to another for all items in the collection. - EDIT_FIELD_DATA: Updates field data for items that match the specified filter. - UPDATE_PUBLISH_STATUS: In collections that have the Publish plugin, updates the publish status of items that match the specified filter. Return type: PROMISE - ONE-OF: - name: deleteByQueryOptions | type: DeleteByQueryOptions | description: Options for tasks of the type `DELETE_BY_QUERY`. - name: dataCollectionId | type: string | description: GUID of the collection from which to delete the items that match the filter. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing) from which to delete item. Default: `LIVE`. - enum: - SANDBOX: Collection [sandbox environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections). - SANDBOX_PREFERRED: If the [collection's sandbox environment is enabled](https://support.wix.com/en/article/cms-accessing-and-syncing-your-sandbox-and-live-collections#enabling-sandbox-collections), run the task in the collection's sandbox environment. If not, run the task in the collection's live environment. - LIVE: Collection [live environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#live-collections). - name: filter | type: object | description: Query filter. If not specified, all items are deleted. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: appOptions | type: object | description: Additional options specific to the [Wix app collection](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) you are querying. Learn more about [querying Wix app collections](https://dev.wix.com/docs/develop-websites/articles/wix-apps/wix-app-collections/querying-wix-app-collections.md). - name: publishPluginOptions | type: PublishPluginOptions | description: Options for the [Publish plugin](https://support.wix.com/en/article/cms-controlling-live-site-item-visibility-from-your-collection). This plugin allows items in a [data collection](https://dev.wix.com/docs/rest/business-solutions/cms/data-collections/data-collection-object.md) to be marked as draft or published. Published items are visible to site visitors, while draft items are not. - name: includeDraftItems | type: boolean | description: Whether to include draft items. When `true`, both published and draft items are affected. Default: `false`. - name: copyFieldDataOptions | type: CopyFieldDataOptions | description: Options for tasks of the type `COPY_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to copy and write item field data. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to copy and write field data. Default: `LIVE`. - name: sourceFieldKey | type: string | description: GUID of the field to copy data from. - name: targetFieldKey | type: string | description: GUID of the field to copy data to. - name: editFieldDataOptions | type: EditFieldDataOptions | description: Options for tasks of the type `EDIT_FIELD_DATA`. - name: dataCollectionId | type: string | description: GUID of the collection in which to edit the specified field. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to edit the specified field. Default: `LIVE`. - name: filter | type: object | description: Query filter. Only items that match the filter are edited. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: fieldKey | type: string | description: GUID of the field to update. - name: operations | type: Operations | description: Operations to perform on the specified field. - name: addItems | type: array | description: Add elements to a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - ONE-OF: - name: nullValue | type: | description: - name: numberValue | type: number | description: - name: stringValue | type: string | description: - name: boolValue | type: boolean | description: - name: structValue | type: object | description: - name: listValue | type: ListValue | description: - name: values | type: array | description: - name: removeItems | type: array | description: Remove elements from a field of type Array. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: replaceItems | type: array | description: In a field of type Array, replace all matching elements. In a field of another type, replace all matching values. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: from | type: Value | description: Value or array element to replace. - name: to | type: Value | description: Value or array element to replace with. - name: removeDuplicates | type: boolean | description: In a field of type Array, remove duplicate elements. Default: `false`. Learn more about [field types](https://support.wix.com/en/article/cms-formerly-content-manager-about-your-collection-fields#field-type). - name: updatePublishStatusOptions | type: UpdatePublishStatusOptions | description: Options for tasks of the type `UPDATE_PUBLISH_STATUS`. - ONE-OF: - name: scheduleDraftStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_DRAFT_STATUS` operation, options for scheduling the status update to `DRAFT`. - name: date | type: Date | description: When to update the item's publish status. - name: schedulePublishedStatusOptions | type: ScheduleOperation | description: In a `SCHEDULE_PUBLISHED_STATUS` operation, options for scheduling the status update to `PUBLISHED`. - name: dataCollectionId | type: string | description: GUID of the collection whose items' publish status is to be updated. - name: environment | type: Environment | description: [Collection environment](https://support.wix.com/en/article/cms-about-sandbox-and-live-collections-and-syncing#sandbox-collections) in which to update the publish status of the items. Default: `LIVE`. - name: filter | type: object | description: Query filter. If not specified, the publish status of all items is updated. Learn about working with [API query language](https://dev.wix.com/docs/rest/articles/getting-started/api-query-language.md). - name: operation | type: Operation | description: Publish status update operation. - enum: - SET_PUBLISHED_STATUS: Update the publish status of all items that match the filter to `PUBLISHED`. - SET_DRAFT_STATUS: Update the publish status of all items that match the filter to `DRAFT`. - SCHEDULE_PUBLISHED_STATUS: Schedule when to update the publish status of all items that match the filter to `PUBLISHED`. - SCHEDULE_DRAFT_STATUS: Schedule when to update the publish status of all items that match the filter to `DRAFT`. - CANCEL_SCHEDULING: Cancel all scheduled status updates. - name: _id | type: string | description: Task GUID. - name: type | type: Type | description: Task type. - enum: - DELETE_BY_QUERY: Deletes all items that match the specified filter. - COPY_FIELD_DATA: Copies data from one field to another for all items in the collection. - EDIT_FIELD_DATA: Updates field data for items that match the specified filter. - UPDATE_PUBLISH_STATUS: In collections that have the Publish plugin, updates the publish status of items that match the specified filter. - name: status | type: Status | description: Task status. - enum: - NEW: Task was created but has not started. - RUNNING: Task is currently running. - COMPLETED: Task has completed. Partial errors are listed in `failures`. - FAILED: Task has failed. Tasks can fail due to errors or because they were cancelled. Failures are listed in `failures`. Cancelled tasks have a failure `code` value of `CANCELLED`, and no associated failure `data`. - name: startedAt | type: Date | description: Task start time. Empty if the task status is `NEW`. - name: finishedAt | type: Date | description: Task finish time. Empty until the task status updates to `COMPLETED` or `FAILED`. - name: itemsFailed | type: integer | description: Number of items whose processing failed. - name: failures | type: array | description: List of errors generated during the task. Learn more about [Wix Data error codes](https://dev.wix.com/docs/sdk/backend-modules/data/wix-data-error-codes.md). - name: code | type: string | description: Error code. - name: description | type: string | description: Description of the error. - name: data | type: object | description: Data related to the error. - name: estimatedItemCount | type: integer | description: Estimated number of items affected by the task. - name: itemsSucceeded | type: integer | description: Number of items successfully processed so far. ``` ### Examples ### createTask ```javascript import { tasks } from '@wix/data'; async function createTask(task) { const response = await tasks.createTask(task); }; ``` ### createTask (with elevated permissions) ```javascript import { tasks } from '@wix/data'; import { auth } from '@wix/essentials'; async function myCreateTaskMethod(task) { const elevatedCreateTask = auth.elevate(tasks.createTask); const response = await elevatedCreateTask(task); } ``` ### createTask (self-hosted) Self-hosted SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md). ```javascript import { createClient } from '@wix/sdk'; import { tasks } from '@wix/data'; // Import the auth strategy for the relevant access type // Import the relevant host module if needed const myWixClient = createClient ({ modules: { tasks }, // Include the auth strategy and host as relevant }); async function createTask(task) { const response = await myWixClient.tasks.createTask(task); }; ``` ---