REST API Reference

SureCommerce REST API

Token-authenticated API for integrating SureCommerce with mobile apps, third-party services, and custom frontends.

🔸 Overview

Base URL

https://yourdomain.com/api/v1

Response Format

JSON (Content-Type: application/json)

All API responses follow a consistent envelope structure:

{
  "success": true,
  "data": { ... },       // resource data or array
  "message": "...",      // optional human-readable message
  "meta": { ... }        // pagination info (list endpoints only)
}

Pagination meta (list endpoints)

{
  "meta": {
    "current_page": 1,
    "last_page": 5,
    "per_page": 15,
    "total": 73
  }
}

🔒 Authentication

All API endpoints require a valid Bearer token. Requests without a token receive 401 Unauthorized.

Sending the token

Include the token in the Authorization header of every request:

GET /api/v1/products HTTP/1.1
Host: yourdomain.com
Authorization: Bearer YOUR_API_TOKEN
Accept: application/json

Example with cURL

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
     -H "Accept: application/json" \
     https://yourdomain.com/api/v1/products

Rate Limiting

Each API token has a configurable rate limit (requests per minute). When exceeded, the API returns 429 Too Many Requests. The limit can be adjusted per client in Admin → API Clients.

🔑 Token Management

API tokens are managed from the admin panel. Each token belongs to an API Client record that controls its name, status, and rate limit.

Creating a token

  1. Login to the Admin Panel at /admin
  2. Navigate to Admin → API Clients
  3. Click Add New and enter a name for the client (e.g., "Mobile App")
  4. Save. Then click Generate Token on the client detail page
  5. Copy the token immediately — it will not be shown again in full
You can generate multiple tokens per client and revoke individual tokens at any time from Admin → API Clients → [client] → Tokens.

Revoking a token

Go to Admin → API Clients → [client name] and click Revoke next to the token. The token becomes invalid immediately.

Updating rate limits

On the client detail page click Update Config to change the requests-per-minute limit for that client.

🛍 Products

GET /api/v1/products List products

Returns a paginated list of active products.

Query parameters

Parameter Type Description
searchstringFilter by product name (partial match)
category_idintegerFilter by category ID
brand_idintegerFilter by brand ID
sortstringnewest (default) | price_asc | price_desc
per_pageintegerItems per page (default: 15, max: 100)
pageintegerPage number (default: 1)

Example response

{
  "success": true,
  "data": [
    {
      "id": 1,
      "categoryId": 3,
      "brandId": 2,
      "defaultVariantId": 5,
      "minPrice": 1990000,
      "price": 2190000,
      "priceVariant": 2190000,
      "priceOriginal": 2490000,
      "priceOld": 2490000,
      "priceOldVariant": 2490000,
      "hasFlashSale": false,
      "sku": "SP001-RED-M",
      "name": "Product Name",
      "slug": "product-name",
      "image": "https://yourdomain.com/uploads/products/image.jpg",
      "slide": [],
      "status": "published",
      "createdAt": "2026-01-15T10:30:00.000000Z",
      "updatedAt": "2026-06-01T08:00:00.000000Z",
      "category": { "id": 3, "name": "Category Name", "slug": "category-name" },
      "brand": { "id": 2, "name": "Brand Name", "slug": "brand-name" }
    }
  ],
  "meta": {
    "current_page": 1,
    "last_page": 5,
    "per_page": 15,
    "total": 73
  }
}
GET /api/v1/products/{id} Get product detail

Returns full product data including detail, accessories, technical specifications, and warranty info. Also includes variants and attributes.

Additional fields returned (vs list)

  • description — short description
  • detail — full HTML description
  • technicalSpecifications — array of specification rows
  • warrantyDuration, warrantyDurationType, warrantyInfo
  • relatedProductIds — array of product IDs
  • accessoryIds — array of accessory product IDs
  • attributes — product attributes array
  • variants — product variants array

Error response (404)

{ "success": false, "message": "Product not found." }

📁 Categories

GET /api/v1/categories List categories

Returns paginated active categories. Supports per_page and page query parameters.

Response fields

id, name, slug, image, icon, description, parentId, order, status, productCount

GET /api/v1/categories/{id} Get category detail

Returns a single category. Returns 404 if not found or inactive.

🏷 Brands

GET /api/v1/brands List brands

Returns paginated active brands. Supports per_page and page query parameters.

Response fields: id, name, slug, logo, website, description, order, status

GET /api/v1/brands/{id} Get brand detail

Returns a single brand. Returns 404 if not found or inactive.

📦 Orders

GET /api/v1/orders List orders

Returns paginated orders. Supports per_page, page, and status filter.

Response fields

id, code, status, shippingFee, couponAmount, totalAmount, note, createdAt, customer (name, phone, email), payment (method, status)

GET /api/v1/orders/{id} Get order detail

Returns full order detail including line items, shipping info, shipping history, and order history log.

Additional fields (vs list)

  • orderDetail — array of line items (product, variant, qty, price, flashSaleName)
  • shipping — carrier, tracking code, shipping method, shipping history
  • customer — full customer info including VAT details
  • orderHistory — array of history events with type, label, data, time

Example orderHistory entry

{
  "id": 10,
  "type": "delivering",
  "label": "Delivering",
  "data": null,
  "adminUserId": 1,
  "time": "2026-06-15T14:20:00.000000Z"
}
PATCH /api/v1/orders/{id}/status Update order status

Transitions an order through its lifecycle. Only valid transitions are accepted — attempting an out-of-sequence change returns 422 with the list of allowed next statuses.

Status values

Value Constant Meaning
1STATUS_NEWNew — awaiting processing
2STATUS_RECEIVEDAccepted / Processing
21STATUS_DELIVERYOut for delivery
4STATUS_SUCCESSCompleted successfully
3STATUS_CANCELCancelled (stock restored)
31STATUS_CANCEL_USERCancel requested by customer

Allowed transitions

Current status Can transition to Side effects
1 — NEW 2 — RECEIVED History logged · Email sent to customer
2 — RECEIVED 21, 4, 3 History logged · Email sent · Stock restored on CANCEL
21 — DELIVERY 4, 3 History logged · Email sent · Stock restored on CANCEL
31 — CANCEL_USER 3, 2 Stock restored on CANCEL · History logged
4 — SUCCESS Terminal state
3 — CANCEL Terminal state

Request body (JSON)

Field Type Description
statusinteger (required)Target status value (see table above)
reasonstring (optional)Cancellation reason — only used when transitioning to status 3

Example — accept order (NEW → RECEIVED)

PATCH /api/v1/orders/42/status
Authorization: Bearer {token}
Content-Type: application/json

{ "status": 2 }

Example — cancel order (RECEIVED → CANCEL)

PATCH /api/v1/orders/42/status
Authorization: Bearer {token}
Content-Type: application/json

{ "status": 3, "reason": "Customer requested cancellation" }

Success response 200

{
  "success": true,
  "message": "Order status updated.",
  "data": { "id": 42, "code": "ORD-20260714", "status": 2, ... }
}

Invalid transition response 422

{
  "success": false,
  "message": "Status transition not allowed.",
  "current": 1,
  "allowed": [2]
}

🔒 Warranty

Three warranty endpoints cover the full warranty flow: check (verify a serial code before activation), activate (register the warranty), and lookup (search existing warranties by phone or serial).
GET /api/v1/warranty/check Check warranty status

Query parameters

ParameterTypeDescription
codestring (required)Serial / warranty code to check

Possible responses

// Can be activated (200)
{
  "success": true,
  "data": {
    "can_activate": true,
    "serial": "SC20260001",
    "product_name": "Product Name",
    "sku": "SP001",
    "warranty_period": "12 months"
  }
}

// Already activated (422)
{
  "success": false,
  "message": "Warranty already activated.",
  "data": {
    "already_activated": true,
    "activation_date": "15/01/2026",
    "end_date": "15/01/2027"
  }
}

// Counterfeit detected (422)
{
  "success": false,
  "is_counterfeit": true,
  "risk_level": "high",
  "message": "counterfeit_not_exist"
}
POST /api/v1/warranty/activate Activate warranty

Request body (JSON)

FieldTypeRequiredDescription
codestringYesSerial / warranty code
namestringYesCustomer full name
phonestringYesCustomer phone number
emailstringNoCustomer email — confirmation sent if provided
addressstringNoCustomer address

Success response (200)

{
  "success": true,
  "message": "Warranty activated successfully.",
  "data": {
    "code": "SC20260001",
    "activation_date": "13/07/2026",
    "warranty_end": "13/07/2027"
  }
}

An activation confirmation email is automatically queued if email was provided.

POST /api/v1/warranty/lookup Lookup warranty by serial or phone

Searches for warranty info. Short numeric values (< 12 chars or starting with 0 / +) are treated as phone numbers and return all matching warranties. Longer strings are treated as serial numbers and return a single warranty.

Request body (JSON)

{ "serial": "0901234567" }     // phone lookup
{ "serial": "SC20260001" }    // serial lookup

Success response — serial lookup (200)

{
  "success": true,
  "data": {
    "serial": "SC20260001",
    "product_name": "Product Name",
    "is_activated": true,
    "activation_date": "13/07/2026 09:00",
    "warranty_time": "12 months",
    "expiration_date": "13/07/2027 09:00",
    "days_remaining": 365,
    "customer": {
      "name": "Nguyen Van A",
      "phone": "0901234567",
      "email": "customer@example.com"
    }
  }
}

Success response — phone lookup (200)

{
  "success": true,
  "data": [
    {
      "serial": "SC20260001",
      "product_name": "Product Name",
      "is_activated": true,
      "activation_date": "13/07/2026 09:00",
      "warranty_time": "12 months",
      "expiration_date": "13/07/2027 09:00",
      "days_remaining": 365,
      "customer": { "name": "Nguyen Van A", "phone": "0901234567", "email": null }
    }
  ]
}

Not found (404)

{ "success": false, "message": "Not found." }

⚠️ Error Responses

HTTP Code Meaning Common cause
400Bad RequestMalformed JSON body
401UnauthorizedMissing or invalid token
404Not FoundResource does not exist or is inactive
422Unprocessable EntityValidation failed or business rule violated
429Too Many RequestsRate limit exceeded for this token
500Server ErrorUnexpected server error (check Laravel logs)

Validation error envelope (422)

{
  "success": false,
  "message": "The code field is required.",
  "errors": {
    "code": ["The code field is required."]
  }
}

SureCommerce — REST API Reference

© 2026 DreamTeam. All rights reserved.  |  Install Guide  |  User Guide  |  FAQ