Business API Design Specification - Create Listing

A Business API is a set of logical actions centered around a main data object. These actions can range from simple CRUD operations to complex workflows that implement intricate business logic.

While the term “API” traditionally refers to an interface that allows software systems to interact, in Mindbricks a Business API represents a broader concept. It encapsulates a business workflow around a data object, going beyond basic CRUD operations to include rich, internally coordinated actions that can be fully designed and customized.

This document provides an in-depth explanation of the architectural design of the createListing Business API. It is intended to guide backend architects and developers in maintaining the current design. Additionally, frontend developers and frontend AI agents can use this document to understand how to properly consume this API on the client side.

Main Data Object and CRUD Operation

The createListing Business API is designed to handle a create operation on the Listing data object. This operation is performed under the specified conditions and may include additional, coordinated actions as part of the workflow.

API Description

Create a new classified listing. Sets status to ‘pending_review’ (may be updated by moderator process). Accepts all mandatory fields, accepts premiumType for premium upgrade.

API Frontend Description By The Backend Architect

API Options

API Controllers

A Mindbricks Business API can be accessed through multiple interfaces, including REST, gRPC, WebSocket, Kafka, or Cron. The controllers listed below map the business workflow to a specific interface, enabling consistent interaction regardless of the communication channel.

REST Controller

The createListing Business API includes a REST controller that can be triggered via the following route:

/v1/listings

By sending a request to this route using the service API address, you can execute this Business API. Parameters can be provided in multiple HTTP locations, including the URL path, URL query, request body, and request headers. Detailed information about these parameters is provided in the Parameters section.

MCP Tool

REST controllers also expose the Business API as a tool in the MCP, making it accessible to AI agents. This createListing Business API will be registered as a tool on the MCP server within the service binding.

API Parameters

The createListing Business API has 22 parameters that must be sent from the controller. Note that all parameters, except session and Redis parameters, should be provided by the client.

Business API parameters can be:

Regular Parameters

Name Type Required Default Location Data Path
listingId ID No - body listingId
Description: This id paremeter is used to create the data object with a given specific id. Leave null for automatic id.
attributes Object No - body attributes
Description: JSON object for custom per-category attributes (structured as required by category schema).
categoryId ID Yes - body categoryId
Description: Main category for the listing (categoryLocation:category).
condition Enum Yes - body condition
Description: Item condition: new, used, other.
contactEmail String No - body contactEmail
Description: Contact email (recommended to send via platform only).
contactPhone String No - body contactPhone
Description: Display phone/contact for listing; may be masked by front end.
currency String Yes - body currency
Description: Currency (ISO-4217 code, e.g. ‘TRY’, ‘USD’).
description Text Yes - body description
Description: Full description/body of listing.
expiresAt Date No - body expiresAt
Description: UTC expiry for listing; after this, listing is automatically expired.
favoriteCount Integer Yes - body favoriteCount
Description: Favorite count (updated asynchronously by favorite service, not directly settable by user).
isPremium Boolean Yes - body isPremium
Description: If true, the listing is premium (highlighted/pinned, eligible for special placement).
listingType Enum Yes - body listingType
Description: Type of listing (sale, rent, service, etc.).
locationId ID Yes - body locationId
Description: Location (categoryLocation:location).
_paymentConfirmation String No - body _paymentConfirmation
Description: Stripe payment result details (Stripe webhook metadata, internal use only).
premiumExpiry Date No - body premiumExpiry
Description: UTC date when premium status expires. Null if not premium or not applicable.
premiumType Enum No - body premiumType
Description: Which premium package (gold, silver, none, etc.).
price Double Yes - body price
Description: Listing price.
status Enum Yes - body status
Description: Lifecycle status: pending_review, active, denied, sold, expired, deleted.
subcategoryId ID No - body subcategoryId
Description: Subcategory for the listing, can be null for top-level (categoryLocation:category).
title String Yes - body title
Description: Listing title, short and clear.
userId ID Yes - session userId
Description: Owner (poster) of the listing (auth:user).
viewsCount Integer Yes - body viewsCount
Description: View count (updated asynchronously; not directly settable by user).

Parameter Transformations

Some parameters are post-processed using transform scripts after being read from the request but before validation or workflow execution. Only parameters with a transform script are listed below.

No parameters are transformed in this API.

AUTH Configuration

The authentication and authorization configuration defines the core access rules for the createListing Business API. These checks are applied after parameter validation and before executing the main business logic.

While these settings cover the most common scenarios, more fine-grained or conditional access control—such as permissions based on object context, nested memberships, or custom workflows—should be implemented using explicit actions like PermissionCheckAction, MembershipCheckAction, or ObjectPermissionCheckAction.

Login Requirement

This API requires login (loginRequired = true). Requests from non-logged-in users will return a 401 Unauthorized error. Login is necessary but not sufficient, as additional role, permission, or other authorization checks may still apply.


Ownership Checks


Role and Permission Settings


Data Clause

Defines custom field-value assignments used to modify or augment the default payload for create and update operations. These settings override values derived from the session or parameters if explicitly provided.", Note that a default data clause is always prepared by Mindbricks using data property settings, however any property in the data clause can be override by Data Clause Settings.

Custom Data Clause Override No custom data clause override configured

Actual Data Clause

The business api will use the following data clause. Note that any calculated value will be added to the data clause in the api manager.

{
  id: this.listingId,
  attributes: this.attributes ? (typeof this.attributes == 'string' ? JSON.parse(this.attributes) : this.attributes) : null,
  categoryId: this.categoryId,
  condition: this.condition,
  contactEmail: this.contactEmail,
  contactPhone: this.contactPhone,
  currency: this.currency,
  description: this.description,
  expiresAt: this.expiresAt,
  favoriteCount: this.favoriteCount,
  isPremium: this.isPremium,
  listingType: this.listingType,
  locationId: this.locationId,
  _paymentConfirmation: this._paymentConfirmation,
  premiumExpiry: this.premiumExpiry,
  premiumType: this.premiumType,
  price: this.price,
  status: this.status,
  subcategoryId: this.subcategoryId,
  title: this.title,
  userId: this.userId,
  viewsCount: this.viewsCount,
  isActive: true,
  _archivedAt: null,
}

Business Logic Workflow

[1] Step : startBusinessApi

Manager initializes context, populates session and request objects, prepares internal structures for parameter handling and workflow execution.

You can use the following settings to change some behavior of this step. apiOptions, restSettings, grpcSettings, kafkaSettings, socketSettings, cronSettings

[2] Step : readParameters

Manager reads input parameters, normalizes missing values, applies default type casting, and stores them in the API context.

You can use the following settings to change some behavior of this step. customParameters, redisParameters

[3] Step : transposeParameters

Manager transforms parameters, computes derived values, flattens or remaps arrays/objects, and adjusts formats for downstream processing.


[4] Step : checkParameters

Manager executes built-in validations: required field checks, type enforcement, and basic business rules. Prevents operation if validation fails.


[5] Step : checkBasicAuth

Manager performs authentication and authorization checks: verifies session, user roles, permissions, and tenant restrictions.

You can use the following settings to change some behavior of this step. authOptions

[6] Step : buildDataClause

Manager constructs the final data object for creation, fills auto-generated fields (IDs, timestamps, owner fields), and ensures schema consistency.

You can use the following settings to change some behavior of this step. dataClause

[7] Step : mainCreateOperation

Manager executes the database insert operation, updates indexes/caches, and triggers internal post-processing like linked default records.


[8] Step : buildOutput

Manager shapes the response: masks sensitive fields, resolves linked references, and formats output according to API contract.


[9] Step : sendResponse

Manager sends the response to the client and finalizes internal tasks like flushing logs or updating session state.


[10] Step : raiseApiEvent

Manager triggers API-level events (Kafka, WebSocket, async workflows) as the final internal step.


Rest Usage

Rest Client Parameters

Client parameters are the api parameters that are visible to client and will be populated by the client. Note that some api parameters are not visible to client because they are populated by internal system, session, calculation or joint sources.

The createListing api has got 19 regular client parameters

Parameter Type Required Population
attributes Object false request.body?.[“attributes”]
categoryId ID true request.body?.[“categoryId”]
condition Enum true request.body?.[“condition”]
contactEmail String false request.body?.[“contactEmail”]
contactPhone String false request.body?.[“contactPhone”]
currency String true request.body?.[“currency”]
description Text true request.body?.[“description”]
expiresAt Date false request.body?.[“expiresAt”]
favoriteCount Integer true request.body?.[“favoriteCount”]
listingType Enum true request.body?.[“listingType”]
locationId ID true request.body?.[“locationId”]
_paymentConfirmation String false request.body?.[“_paymentConfirmation”]
premiumExpiry Date false request.body?.[“premiumExpiry”]
premiumType Enum false request.body?.[“premiumType”]
price Double true request.body?.[“price”]
status Enum true request.body?.[“status”]
subcategoryId ID false request.body?.[“subcategoryId”]
title String true request.body?.[“title”]
viewsCount Integer true request.body?.[“viewsCount”]

REST Request

To access the api you can use the REST controller with the path POST /v1/listings

  axios({
    method: 'POST',
    url: '/v1/listings',
    data: {
            attributes:"Object",  
            categoryId:"ID",  
            condition:"Enum",  
            contactEmail:"String",  
            contactPhone:"String",  
            currency:"String",  
            description:"Text",  
            expiresAt:"Date",  
            favoriteCount:"Integer",  
            listingType:"Enum",  
            locationId:"ID",  
            _paymentConfirmation:"String",  
            premiumExpiry:"Date",  
            premiumType:"Enum",  
            price:"Double",  
            status:"Enum",  
            subcategoryId:"ID",  
            title:"String",  
            viewsCount:"Integer",  
    
    },
    params: {
    
        }
  });

REST Response

The API response is encapsulated within a JSON envelope. Successful operations return an HTTP status code of 200 for get, list, update, or delete requests, and 201 for create requests. Each successful response includes a "status": "OK" property. For error handling, refer to the “Error Response” section.

Following JSON represents the most comprehensive form of the listing object in the respones. However, some properties may be omitted based on the object’s internal logic.

{
	"status": "OK",
	"statusCode": "201",
	"elapsedMs": 126,
	"ssoTime": 120,
	"source": "db",
	"cacheKey": "hexCode",
	"userId": "ID",
	"sessionId": "ID",
	"requestId": "ID",
	"dataName": "listing",
	"method": "POST",
	"action": "create",
	"appVersion": "Version",
	"rowCount": 1,
	"listing": {
		"id": "ID",
		"attributes": "Object",
		"categoryId": "ID",
		"condition": "Enum",
		"condition_idx": "Integer",
		"contactEmail": "String",
		"contactPhone": "String",
		"currency": "String",
		"description": "Text",
		"expiresAt": "Date",
		"favoriteCount": "Integer",
		"isPremium": "Boolean",
		"listingType": "Enum",
		"listingType_idx": "Integer",
		"locationId": "ID",
		"_paymentConfirmation": "String",
		"premiumExpiry": "Date",
		"premiumType": "Enum",
		"premiumType_idx": "Integer",
		"price": "Double",
		"status": "Enum",
		"status_idx": "Integer",
		"subcategoryId": "ID",
		"title": "String",
		"userId": "ID",
		"viewsCount": "Integer",
		"paymentConfirmation": "Enum",
		"paymentConfirmation_idx": "Integer",
		"isActive": true,
		"recordVersion": "Integer",
		"createdAt": "Date",
		"updatedAt": "Date",
		"_owner": "ID"
	}
}