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.
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 separate access tokens for each scope based on the operations you need to perform.

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
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:
    • IN_PROGRESS: Operation is currently executing.
    • COMPLETED: All rules processed successfully.
    • FAILED: Operation failed before processing any rules.
    • COMPLETED_WITH_ERRORS: Some rules succeeded, others failed.
  • Individual status for each rule
  • Error messages for any failed rules
Rules included in an active bulk operation cannot be modified until the operation completes. The pendingInBulkOperation 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 pendingInBulkOperation 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.