Skip to main content
The Rules and Rewrites API for Commerce Studio enables you to create and manage merchandising rules and query rewrites programmatically. This API supports enterprise automation workflows, cross-environment synchronization, and integration with internal tools. For complete details about all of its endpoints, methods, and parameters, see the Rules and Rewrites API reference.

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.
For visual rule creation and management, use the Commerce Studio UI. The API is designed for programmatic workflows where automation and integration are required.

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.
Use external IDs to maintain stable references across environments. For example, assign an external ID like promo-summer-2026 to ensure the same rule can be identified and updated consistently in development, QA, and production.
External IDs must be unique within a Commerce Studio instance. The API prevents duplicate external IDs to maintain rule integrity.

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)
Request one access token that lists every scope you need. If an integration only needs one capability, request only that scope. To keep permissions separate for different integrations, use a separate service account for each one.

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.
If you don’t already have a Lucidworks service account of type “API”, complete the following steps:
1
In Lucidworks Platform, go to Settings > Service Accounts.
2
Click Create New Service Account.
3
In the New Service Account window, be sure to select API as the service account type. Enter a name and optionally a description to help you remember what this account is for.
4
Click Create New Service Account. The new account appears in the list. Click the account you created to find the Client ID and Client Secret you need to access the API.
You’ll need the following information to access the API:
  • Commerce Studio ID: Your Commerce Studio instance identifier
  • Client ID: From your service account
  • Client Secret: From your service account
1

Find your Commerce Studio ID

Your Commerce Studio ID is part of your Commerce Studio URL. For example, if your Commerce Studio URL is https://COMMERCE_STUDIO_ID.experiencemanager.lucidworks.com, your Commerce Studio ID is COMMERCE_STUDIO_ID.
2

Get your service account credentials

In Lucidworks Platform, go to Settings > Service Accounts and click the service account you created. Copy the Client ID and Client Secret.
1

Fetch an access token

Before making API requests, you need to authenticate and obtain an access token.Send a POST request to the authentication endpoint:
Replace API_SCOPE with one or more of these (as a space-separated list):
  • commercestudio.rules for rule operations
  • commercestudio.rewrites for query rewrite operations
  • commercestudio.bulkoperations for bulk operations
In the URL, separate the scopes with %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:
Some HTTP clients perform the base64 encoding automatically when you provide the client ID as the username and client secret as the password.
A successful response returns:
2

Make API requests

Use the access token in the Authorization header of your API requests:
Replace COMMERCE_STUDIO_ID with your Commerce Studio instance ID.
3

Refresh your token

Access tokens expire after 60 minutes.
Once you request a new token, the previous one is deleted even if it has not yet expired. All subsequent API calls must use the new 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
Bulk operations require an authentication token with the 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 all draft rules tagged 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.
1

Create a bulk operation

Send a POST request to /bulk-operations with the operation type and list of rule IDs or external IDs.The API returns a bulk operation ID and initial status.
2

Monitor operation progress

Poll the bulk operation status using GET /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 by migrateRule. 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, or FAILED
  • Error messages for any failed rules
Rules included in an active bulk operation cannot be modified until the operation completes. The pendingBulkOperation field indicates when a rule is locked by a bulk operation.
3

Handle completion

When the operation reaches a terminal status (COMPLETED, FAILED, or COMPLETED_WITH_ERRORS), review the results.For operations that completed with errors, the response identifies which rules succeeded and which failed.
For detailed information about bulk operation endpoints and parameters, see the Bulk Operations API reference.

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 pendingBulkOperation flag before attempting to update rules.
  • Use external IDs for stability: External IDs make it easier to retry operations and maintain consistency across environments.
For detailed information about bulk operation endpoints and parameters, see the Bulk Operations API reference.

Example workflows

These workflows show how to combine the API’s endpoints to automate common tasks. Each example uses COMMERCE_STUDIO_ID for your Commerce Studio ID and EXAMPLE_ACCESS_TOKEN for an access token with the scopes listed in the workflow.
Create campaign rules as drafts, review them, publish them together, and retire them when the campaign ends.Scopes: commercestudio.rules and commercestudio.bulkoperations
1

Create the campaign rules as drafts

Create each rule with published set to false, a shared tag, and a date range. This example boosts gift card products for queries that contain gift.
The response includes the new rule’s id and its publishState. This example shows a subset of the fields:
The date range limits when the rule takes effect, so the rule stops affecting queries after effectiveEnd even if it stays published.
2

Review the drafts

Review the draft rules in Commerce Studio before you publish them.
3

Publish all of the campaign rules

Publish every draft rule with the campaign tag in one bulk operation:
The response includes the bulk operation’s id and its starting status, PENDING. This example shows a subset of the fields:
4

Check the result

Poll the bulk operation until it reaches a final status:
When the operation finishes, the response shows its final status and the status of each rule. This example shows a subset of the fields:
If the status is COMPLETED_WITH_ERRORS, check each rule’s status in the response and fix or retry the rules that failed.
5

Retire the campaign rules

After the campaign, unpublish or delete the rules by tag with an unpublishRule or deleteRule bulk operation. See Example requests.
Export your rules and rewrites on a schedule and commit them to a source control repository, so you can see what changed and restore earlier versions.Scopes: commercestudio.rules and commercestudio.rewrites
1

Export rules page by page

List rules in pages, sorted so that every export uses the same order:
The response lists the rules in content and the paging details in page. This example shows a subset of the fields:
Increase page until you’ve retrieved every page, using totalPages to know when to stop. Pages start at 0.
Pass filters as query parameters, such as ?searchQuery=vinyl&size=50. Leave out the fields parameter unless you need the extra fields it returns, because it slows down the request and increases the response size.
2

Export rewrites the same way

3

Commit the export

Save the results as JSON files in your repository and commit them. Run the export on a schedule, such as daily, to build a history of changes.
4

Restore a rule or rewrite if needed

To restore a rule or rewrite from your history, send its saved version back with a 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:
You can send the exported JSON as-is. The API ignores read-only fields such as 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-Match header with its current ETag.
    • The ETag is the lastModified value 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 version field as the ETag.
  • External IDs: The externalId is set only when an item is created. A different externalId in a PUT request is ignored.
  • Rewrite types: The type in a rewrite’s PUT request 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.
If the item was deleted, create it again with a POST request to /em-rules or /query-rewrites.
Copy rules and rewrites from one Commerce Studio instance to another, such as from QA to production. Give each rule and rewrite an externalId, so you can identify the same item in every environment.Scopes: commercestudio.bulkoperations and commercestudio.rewrites
1

Migrate the rules

Use a 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:
If the target instance already has a rule with the same 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.
2

Copy the rewrites

Bulk operations apply to rules only, so copy rewrites with individual requests. Get each rewrite from the source instance, then create it in the target instance with the same externalId:
If both instances are in the same workspace, the same access token works for both. A token from a different workspace is rejected with a 403 error, so if the target instance is in another workspace, use a service account from that workspace.
3

Review and publish in the target instance

Review the migrated rules and copied rewrites in the target instance, then publish them.
Delete draft rules that haven’t been changed in a long time.Scopes: commercestudio.rules and commercestudio.bulkoperations
A delete bulk operation can remove many rules at once. Back up your rules first, and test on a small batch before you delete in bulk. See Back up rules and rewrites to version control.
1

Find the rules to delete

List the draft rules that haven’t changed since a cutoff date, and review the results:
2

Test on a small batch

Delete a few of the rules by ID with a deleteRule bulk operation that uses ruleIds, and confirm the result.
3

Delete the rest

Run a 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.
Use an AI tool to draft rules in bulk, then review them before they go live.Scopes: commercestudio.rules and commercestudio.bulkoperations
1

Generate the rule definitions

Give your AI tool the rule schema from the API reference and the rules you want, such as boosts for your top-selling products. Ask it to set published to false, add a tag such as ai-generated, and give each rule an externalId.
2

Create the rules

Send each definition with a POST request to /em-rules. If you get rate limit errors, retry with exponential backoff.
3

Review the drafts

Review the draft rules in Commerce Studio, and edit or delete any that aren’t right.
4

Publish the approved rules

Publish the reviewed rules with a publishRule bulk operation that filters on the ai-generated tag and the DRAFT publish state.