Create New Brand
This endpoint is used to create a new brand in the system. It requires certain fields to form a valid request body and accepts additional optional details.
Endpoint
- URL:
/brands - Method:
POST
Authentication
- Header:
accessToken - Type: Bearer Token
- Value:
<ACCESS-TOKEN>
Request Headers
| Header | Type | Description |
|---|---|---|
Content-Type | string | Must be application/json. |
accessToken | string | Access token for authentication. (required) |
Request Body
The request body should be a JSON object containing the following fields:
Required Fields
| Field | Type | Description |
|---|---|---|
name | string | The name of the brand. |
url | string | URL path segment for the brand. |
Optional Fields
| Field | Type | Description |
|---|---|---|
description | string | A brief description of the brand. Can be empty or omitted. |
image | string | Brand main image. Can be a URL or base64 encoded image data. |
sortOrder | number | Order for sorting brands. Defaults to 0. |
isShow | boolean | Whether the brand is shown. Defaults to true. |
isShowNavBar | boolean | Whether the brand is shown in the navigation bar. Defaults to false. |
seo | object | SEO details including pageTitle, metaKeywords, and metaDescription. |
metaFields | array | List of metadata objects, each containing a code and a value (string, number, or array). |
SEO Object (within seo)
| Field | Type | Description |
|---|---|---|
pageTitle | string | Title for the brand page. |
metaKeywords | string | Meta keywords for SEO. |
metaDescription | string | Meta description for SEO. |
MetaFields Object
Each object in the metaFields array includes:
| Field | Type | Description |
|---|---|---|
code | string | Code for the metadata field. |
value | mixed | Value associated with the metadata (string, number, or array). |
Sample Request Body
{
"name": "Nike",
"url": "nike",
"description": "Just Do It",
"isFeatured": true,
"isShow": true,
"seo": {
"pageTitle": "Nike Brand",
"metaKeywords": "nike, sports, shoes",
"metaDescription": "Official Nike brand page"
}
}
Sample Request with Base64 Image
{
"name": "Adidas",
"url": "adidas",
"description": "Impossible is Nothing",
"isFeatured": true,
"isShow": true
}
Response
- Status Code: 201 Created
Success Response Body
{
"success": true,
"message": "Brand added successfully",
"data": {
"id": "new_brand_id",
"name": "Nike",
"url": "nike",
"description": "Just Do It",
"image": null,
"productCount": 0,
"sortOrder": 0,
"isFeatured": true,
"isShow": true,
"isShowNavBar": false,
"seo": {
"pageTitle": "Nike Brand",
"metaKeywords": "nike, sports, shoes",
"metaDescription": "Official Nike brand page"
},
"metaFields": [],
"createdAt": "2024-05-07T11:13:02.066Z",
"updatedAt": "2024-05-07T11:13:02.066Z"
}
}
Success Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | Indicates whether the brand was created successfully. |
message | string | A message conveying the outcome of the operation. |
data | object | Contains details about the newly created brand. See Brand Data Object |
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request: Provided data is invalid or malformed. |
| 401 | Unauthorized: Access token is invalid or missing. |
| 500 | Internal Server Error: An error occurred on the server. |
Image Handling
The API supports both:
- Direct URLs - Pass image URL as string
- Base64 encoded images - Automatically uploaded to storage
When providing base64 encoded images, use the format:
data:image/png;base64,<encoded_data>
The system will automatically:
- Upload the image to storage
- Generate a proper image URL
- Store the URL in the brand record
Notes
- The
productCountfield is automatically initialized to 0 and will be updated as products are assigned to the brand. - If
urlcontains special characters or spaces, they will be automatically converted to a URL-friendly format. - Base64 images are automatically uploaded and converted to permanent URLs.
- The brand data is automatically synced with Elasticsearch for search functionality.