Skip to main content

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

HeaderTypeDescription
Content-TypestringMust be application/json.
accessTokenstringAccess token for authentication. (required)

Request Body

The request body should be a JSON object containing the following fields:

Required Fields

FieldTypeDescription
namestringThe name of the brand.
urlstringURL path segment for the brand.

Optional Fields

FieldTypeDescription
descriptionstringA brief description of the brand. Can be empty or omitted.
imagestringBrand main image. Can be a URL or base64 encoded image data.
sortOrdernumberOrder for sorting brands. Defaults to 0.
isShowbooleanWhether the brand is shown. Defaults to true.
isShowNavBarbooleanWhether the brand is shown in the navigation bar. Defaults to false.
seoobjectSEO details including pageTitle, metaKeywords, and metaDescription.
metaFieldsarrayList of metadata objects, each containing a code and a value (string, number, or array).

SEO Object (within seo)

FieldTypeDescription
pageTitlestringTitle for the brand page.
metaKeywordsstringMeta keywords for SEO.
metaDescriptionstringMeta description for SEO.

MetaFields Object

Each object in the metaFields array includes:

FieldTypeDescription
codestringCode for the metadata field.
valuemixedValue 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

FieldTypeDescription
successbooleanIndicates whether the brand was created successfully.
messagestringA message conveying the outcome of the operation.
dataobjectContains details about the newly created brand. See Brand Data Object

Error Responses

Status CodeDescription
400Bad Request: Provided data is invalid or malformed.
401Unauthorized: Access token is invalid or missing.
500Internal Server Error: An error occurred on the server.

Image Handling

The API supports both:

  1. Direct URLs - Pass image URL as string
  2. 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 productCount field is automatically initialized to 0 and will be updated as products are assigned to the brand.
  • If url contains 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.