When to use this API
The Rules and Rewrites API enables the following use cases:- Automate rule deployment: Create and update rules and rewrites through CI/CD (continuous integration/continuous deployment) pipelines or automated workflows.
- Synchronize across environments: Maintain consistent rules and rewrites across development, QA (quality assurance), and production environments.
- Manage rules at scale: Efficiently handle large rule sets that are impractical to manage through the UI (user interface) alone.
- Fallback with version control: Fetch rules and rewrites, then commit them to your source control repository at intervals so you can easily revert to earlier versions if needed.
- Integrate with AI agents: Use AI to automate creation and updates of rules and rewrites.
- Give tools and teams API access: A Lucidworks Platform administrator creates a service account once, and the tool or team uses its credentials to call the API without a Lucidworks Platform login.
Key concepts
Rule and rewrite identifiers
Every rule and rewrite has two ID fields that you can use interchangeably in API operations:id: Automatically generated UUID (Universally Unique Identifier) assigned by the platform when you create a rule or rewrite. This identifier is unique within the Commerce Studio instance.externalId: Optional user-defined identifier that you can assign when creating a rule or rewrite. This field enables you to maintain your own naming conventions and synchronize rules across multiple environments.
Authentication scopes
The API uses three separate authentication scopes:commercestudio.rules: Required for rule operations (create, read, update, delete rules)commercestudio.rewrites: Required for query rewrite operations (create, read, update, delete rewrites)commercestudio.bulkoperations: Required for bulk operations (publish, unpublish, edit, delete, and migrate operations on multiple rules)
Rate limiting
Platform rate limits apply to all API requests to protect system stability. If you encounter rate limit errors, implement exponential backoff in your integration.Use the Rules and Rewrites API
To use the API, you need a Lucidworks service account. Then you can gather your credentials and begin making API calls. For complete details about API endpoints, methods, and parameters, see the Commerce Studio Rules and Rewrites API reference.Create a service account
Create a service account
Gather your credentials
Gather your credentials
- Commerce Studio ID: Your Commerce Studio instance identifier
- Client ID: From your service account
- Client Secret: From your service account
Find your Commerce Studio ID
https://COMMERCE_STUDIO_ID.experiencemanager.lucidworks.com, your Commerce Studio ID is COMMERCE_STUDIO_ID.Get your service account credentials
Access the API
Access the API
Fetch an access token
API_SCOPE with one or more of these (as a space-separated list):commercestudio.rulesfor rule operationscommercestudio.rewritesfor query rewrite operationscommercestudio.bulkoperationsfor bulk operations
%20, the encoded form of a space.
For example, to request all three scopes in one token, use scope=commercestudio.rules%20commercestudio.rewrites%20commercestudio.bulkoperations.The Authorization header uses basic authentication with your base64-encoded client ID and client secret.
You can encode your credentials using:Make API requests
Authorization header of your API requests:COMMERCE_STUDIO_ID with your Commerce Studio instance ID.Refresh your token
Bulk operations
Bulk operations enable you to perform actions on multiple rules simultaneously. This is useful for scenarios like these:- Publishing or unpublishing large sets of rules at once
- Applying consistent edits across multiple rules
- Deleting obsolete rules in batches
- Migrating rule sets between Commerce Studio instances
commercestudio.bulkoperations scope.
See Authentication scopes.Supported bulk operations
The API supports these bulk operation types:publishRule: Make multiple rules active simultaneously.unpublishRule: Deactivate multiple rules at once.editRule: Apply the same updates to multiple rules.deleteRule: Remove multiple rules in one operation.migrateRule: Copy rules to another Commerce Studio instance.
Example requests
Each bulk operation is a POST request to/bulk-operations.
The request body’s type field determines which operation runs, and you can target rules by ID, external ID, or a specification filter (or a combination of all three), as shown in these examples:
- Publish
- Unpublish
- Edit
- Delete
- Migrate
holiday-2026.How bulk operations work
Bulk operations execute asynchronously. When you create a bulk operation, the API returns immediately with an operation ID. You can then poll the operation status to track progress.Create a bulk operation
/bulk-operations with the operation type and list of rule IDs or external IDs.The API returns a bulk operation ID and initial status.Monitor operation progress
/bulk-operations/{id}.The response includes the following information:-
Overall operation status:
PENDING: The operation hasn’t started or is still processing rules.WAITING: Used only bymigrateRule. All rules have been sent, and the operation is waiting for the target instance to confirm each one.COMPLETED: All rules processed successfully.COMPLETED_WITH_ERRORS: All rules were processed, but some failed.FAILED: An unrecoverable error stopped the operation before it attempted every rule.
-
Individual status for each rule:
PENDING,WAITING,COMPLETED, orFAILED - Error messages for any failed rules
Handle completion
COMPLETED, FAILED, or COMPLETED_WITH_ERRORS), review the results.For operations that completed with errors, the response identifies which rules succeeded and which failed.Best practices
Follow these guidelines when using bulk operations:- Start with small batches: Test bulk operations on a small set of rules before scaling up.
- Monitor operation status: Don’t assume success. Always check the final status and handle partial failures.
- Handle errors gracefully: When operations complete with errors, review which rules failed and retry them individually if needed.
- Avoid modifying locked rules: Check the
pendingBulkOperationflag before attempting to update rules. - Use external IDs for stability: External IDs make it easier to retry operations and maintain consistency across environments.
Example workflows
These workflows show how to combine the API’s endpoints to automate common tasks. Each example usesCOMMERCE_STUDIO_ID for your Commerce Studio ID and EXAMPLE_ACCESS_TOKEN for an access token with the scopes listed in the workflow.
Run a seasonal campaign
Run a seasonal campaign
commercestudio.rules and commercestudio.bulkoperationsCreate the campaign rules as drafts
published set to false, a shared tag, and a date range.
This example boosts gift card products for queries that contain gift.id and its publishState. This example shows a subset of the fields:effectiveEnd even if it stays published.Review the drafts
Publish all of the campaign rules
id and its starting status, PENDING. This example shows a subset of the fields:Check the result
COMPLETED_WITH_ERRORS, check each rule’s status in the response and fix or retry the rules that failed.Retire the campaign rules
unpublishRule or deleteRule bulk operation.
See Example requests.Back up rules and rewrites to version control
Back up rules and rewrites to version control
commercestudio.rules and commercestudio.rewritesExport rules page by page
content and the paging details in page. This example shows a subset of the fields:page until you’ve retrieved every page, using totalPages to know when to stop.
Pages start at 0.Export rewrites the same way
Commit the export
Restore a rule or rewrite if needed
PUT request to /em-rules/{id} or /query-rewrites/{id}.
You can use the id or the externalId in the URL.
For example, to restore a rule:id, createdBy, and lastModified, and takes the ID from the URL.- Version check: To make sure no one changed the item since you exported it, send an
If-Matchheader with its current ETag.- The ETag is the
lastModifiedvalue in epoch milliseconds, in double quotes. Every response includes it. - If the item changed, the API returns
412. - Without
If-Match, the API doesn’t check the version. - For rewrites, don’t use the
versionfield as the ETag.
- The ETag is the
- External IDs: The
externalIdis set only when an item is created. A differentexternalIdin aPUTrequest is ignored. - Rewrite types: The
typein a rewrite’sPUTrequest must match the stored rewrite’s type. - Bulk operations: You can’t update a rule while it’s part of a bulk operation that’s still running.
POST request to /em-rules or /query-rewrites.Promote rules and rewrites between environments
Promote rules and rewrites between environments
externalId, so you can identify the same item in every environment.Scopes: commercestudio.bulkoperations and commercestudio.rewritesMigrate the rules
migrateRule bulk operation in the source instance.
Set published to false so the rules arrive as drafts that you can review in the target instance:externalId, that rule fails to migrate with the error A rule with externalId '...' already exists.
The existing rule isn’t overwritten, and no duplicate is created.
The bulk operation then finishes with the status COMPLETED_WITH_ERRORS.You only need access to the source instance to run a migration.Copy the rewrites
externalId:403 error, so if the target instance is in another workspace, use a service account from that workspace.Review and publish in the target instance
Clean up old draft rules
Clean up old draft rules
commercestudio.rules and commercestudio.bulkoperationsFind the rules to delete
Test on a small batch
deleteRule bulk operation that uses ruleIds, and confirm the result.Delete the rest
deleteRule bulk operation with the same filter, and list any rules you want to keep in excludeRuleIds.
See the Delete tab in Example requests.
Then check the bulk operation’s status until it finishes.Create rules with help from AI
Create rules with help from AI
commercestudio.rules and commercestudio.bulkoperationsGenerate the rule definitions
published to false, add a tag such as ai-generated, and give each rule an externalId.Create the rules
POST request to /em-rules.
If you get rate limit errors, retry with exponential backoff.Review the drafts
Publish the approved rules
publishRule bulk operation that filters on the ai-generated tag and the DRAFT publish state.