Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuanSCaicedo/Api-Ecommerce/llms.txt

Use this file to discover all available pages before exploring further.

API Ecommerce provides two complementary promotional systems:
  • Discounts — automatic, date-based campaigns. The discount is applied transparently when a customer browses a product, category, or brand that falls within an active campaign’s date window. No customer action required.
  • Coupons — customer-entered codes applied in the cart. The customer types the code at checkout and the discount is applied if the code is active, has uses remaining, and targets a matching product/category/brand.
Discounts vs. Coupons at a glance: Discounts fire automatically at browse time — the discounted price is shown directly on the product listing. Coupons require the customer to enter a code in the cart before the discount appears. Use discounts for sitewide sales and flash events; use coupons for targeted promotions (influencer codes, loyalty rewards, etc.).
Mutating operations on coupons (store, update, destroy, delete_imagen) are throttled at 10 requests per minute per token. The discount campaign endpoints have no additional throttle middleware beyond the global request rate.

Authentication

All /api/admin/ endpoints require:
Authorization: Bearer <admin_token>
See Products — Authentication for obtaining a token.

Discount Campaigns

List Discounts

GET /api/admin/discounts
Returns a paginated list of discount campaigns, 25 per page, ordered by id descending. Query parameters
Filter by campaign code (SQL LIKE %value%). Codes are auto-generated with PHP’s uniqid().
Response
total
integer
Total matching campaigns across all pages.
discounts
object
Paginated discount collection. Items live under the data key (Laravel ResourceCollection envelope).
discounts.data
array
Array of discount campaign objects. Each object includes id, code, type_discount, discount, start_date, end_date, discount_type, type_campaing, state, created_at, and expanded products, categories, and brands pivot arrays.
{
  "total": 8,
  "discounts": {
    "data": [
      {
        "id": 3,
        "code": "64f2a1c7b3e2a",
        "type_discount": 1,
        "discount": 15,
        "start_date": "2024-07-01",
        "end_date": "2024-07-31",
        "discount_type": 1,
        "type_campaing": 1,
        "state": 1,
        "created_at": "2024-06-15 09:00 AM",
        "products": [],
        "categories": [],
        "brands": []
      }
    ]
  }
}

Create Discount Campaign

POST /api/admin/discounts
A unique code is auto-generated via PHP’s uniqid() — you do not supply a code. Timezone is set to America/Bogota before date validation.
Overlapping date range validation — before creating, the API checks whether any of the targeted products, categories, or brands already has an active campaign of the same type_campaing and discount_type whose date range overlaps the requested window. A conflict returns:
{
  "message": 403,
  "message_text": "El producto Nike Air Max ya tiene un descuento en el rango de fechas seleccionado, que es #64f2a1c7b3e2a"
}
Request headers
HeaderValue
AuthorizationBearer <admin_token>
Content-Typeapplication/json
Body parameters
type_campaing
integer
required
Campaign type. Campaigns of the same type_campaing and discount_type cannot overlap in date range on the same target entity.
ValueMeaning
1Standard campaign
2Flash sale
discount_type
integer
required
What entity type the campaign targets.
ValueTargets
1Specific products
2Specific categories
3Specific brands
type_discount
integer
How the discount amount is interpreted.
ValueMeaning
1Percentage discount
2Fixed amount off
state
integer
1 = active. Only active campaigns are evaluated at browse time.
start_date
string
required
Campaign start date in YYYY-MM-DD format (Bogota timezone).
end_date
string
required
Campaign end date in YYYY-MM-DD format (inclusive; the API adds +1 day when evaluating Carbon::now()->between()).
discount
number
required
Discount value — a percentage (e.g., 15 for 15% off) or a fixed currency amount, depending on type_discount.
product_selected
array
Required when discount_type = 1. Array of objects with id and title for each targeted product.
[{ "id": 7, "title": "Running Shoes Pro" }]
categorie_selected
array
Required when discount_type = 2. Array of objects with id and name for each targeted category.
[{ "id": 1, "name": "Electronics" }]
brand_selected
array
Required when discount_type = 3. Array of objects with id and name for each targeted brand.
[{ "id": 3, "name": "Samsung" }]
Response
message
integer
200 on success, 403 on date-range conflict.
id
integer
The newly created discount campaign ID.
{ "message": 200, "id": 9 }
Example — create a product-level flash sale
curl -X POST https://your-domain.com/api/admin/discounts \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "type_campaing": 2,
    "discount_type": 1,
    "type_discount": 1,
    "state": 1,
    "start_date": "2024-08-01",
    "end_date": "2024-08-03",
    "discount": 20,
    "product_selected": [
      { "id": 7, "title": "Running Shoes Pro" },
      { "id": 12, "title": "Trail Runners X" }
    ],
    "categorie_selected": [],
    "brand_selected": []
  }'
{ "message": 200, "id": 9 }

Get Discount Campaign

GET /api/admin/discounts/{id}
Path parameters
id
integer
required
Discount campaign ID.
Response
discount
object
Full campaign object (via DiscountResource) including id, code, type_discount, discount, start_date, end_date, discount_type, type_campaing, state, created_at, and expanded products, categories, and brands arrays with resolved product/category/brand data.
{
  "discount": {
    "id": 9,
    "code": "64f2a1c7b3e2a",
    "type_discount": 1,
    "discount": 20,
    "start_date": "2024-08-01",
    "end_date": "2024-08-03",
    "discount_type": 1,
    "type_campaing": 2,
    "state": 1,
    "created_at": "2024-07-20 10:00 AM",
    "products": [
      {
        "id": 7,
        "title": "Running Shoes Pro",
        "slug": "running-shoes-pro",
        "imagen": "https://objectstorage.../products/cover.jpg",
        "id_aux": 1
      }
    ],
    "categories": [],
    "brands": []
  }
}

Update Discount Campaign

PUT /api/admin/discounts/{id}
Path parameters
id
integer
required
Discount campaign ID to update.
Body parameters — same as Create Discount Campaign. On update, the existing discount_products, discount_categories, and discount_brands pivot rows are deleted and recreated from the new *_selected arrays. The same overlapping-date-range validation applies (excluding the current campaign ID from the conflict check). Response
{ "message": 200, "id": 9 }

Delete Discount Campaign

DELETE /api/admin/discounts/{id}
Deletes the campaign record. The Discount model’s deleting event automatically cascades the delete to associated discount_products, discount_categories, and discount_brands pivot rows.
Do not delete a campaign that is referenced by an existing sale/order record, as this may break order history calculations.
Path parameters
id
integer
required
Discount campaign ID to delete.
Response
{ "message": 200 }

Coupons

List Coupons

GET /api/admin/cupones
Returns a paginated list of coupons, 15 per page, ordered by id descending. Query parameters
search
string
Filter by coupon code (SQL LIKE %value%).
Response
total
integer
Total matching coupons.
cupones
object
Paginated coupon collection. Items live under the data key (Laravel ResourceCollection envelope).
cupones.data
array
Array of coupon objects. Each includes id, code, type_discount, discount, type_count, num_use, type_cupone, state, created_at, and expanded products, categories, and brands arrays.
{
  "total": 5,
  "cupones": {
    "data": [
      {
        "id": 2,
        "code": "SUMMER20",
        "type_discount": 1,
        "discount": 20,
        "type_count": 2,
        "num_use": 100,
        "type_cupone": 1,
        "state": 1,
        "created_at": "2024-05-01 08:00 AM",
        "products": [],
        "categories": [],
        "brands": []
      }
    ]
  }
}

Get Coupon Config (Dropdowns)

Returns published products, active first-level categories, and active brands for populating coupon target selection dropdowns.
GET /api/admin/cupones/config
Response
products
array
Published products (state = 2) with id, title, slug, and imagen (resolved OCI URL or null).
categories
array
Active first-level categories (state = 1, categorie_second_id = NULL, categorie_third_id = NULL) with id, name, and imagen (resolved OCI URL or null).
brands
array
Active brands (state = 1) with id and name.
{
  "products": [
    { "id": 7, "title": "Running Shoes Pro", "slug": "running-shoes-pro", "imagen": "https://..." }
  ],
  "categories": [
    { "id": 1, "name": "Electronics", "imagen": null }
  ],
  "brands": [
    { "id": 3, "name": "Samsung" }
  ]
}

Create Coupon

POST /api/admin/cupones
Unlike discount campaigns, the coupon code is supplied by the admin and must be unique. Customers enter this code at checkout.
Coupon code must be unique across all coupons. Duplicate codes return {"message": 403, "message_text": "El cupón ya existe"}.
Request headers
HeaderValue
AuthorizationBearer <admin_token>
Content-Typeapplication/json
Body parameters
code
string
required
Coupon code string that customers enter at checkout (e.g., "SUMMER20", "INFLUENCER10"). Must be unique across all coupons.
state
integer
1 = active (can be applied by customers), 0 = inactive.
type_cupone
integer
required
What entity type the coupon targets.
ValueTargets
1Specific products
2Specific categories
3Specific brands
type_discount
integer
required
How the discount is calculated.
ValueMeaning
1Percentage discount
2Fixed amount off
discount
number
required
Discount value — either a percentage (e.g., 20 for 20% off) or a fixed currency amount depending on type_discount.
type_count
integer
required
Usage limit type.
ValueMeaning
1Unlimited uses
2Limited uses — num_use is decremented on each successful application
num_use
integer
Maximum number of times the coupon may be applied. Required when type_count = 2. Decremented automatically on each successful use.
product_selected
array
required
Array of {id} objects for targeted products. Pass an empty array [] when type_cupone is not 1.
categorie_selected
array
required
Array of {id} objects for targeted categories. Pass an empty array [] when type_cupone is not 2.
brand_selected
array
required
Array of {id} objects for targeted brands. Pass an empty array [] when type_cupone is not 3.
Response
message
integer
200 on success, 403 on duplicate code.
id
integer
The newly created coupon ID.
{ "message": 200, "id": 6 }
Example — create a limited-use percentage coupon targeting a category
curl -X POST https://your-domain.com/api/admin/cupones \
  -H "Authorization: Bearer <admin_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "code": "TECH15",
    "state": 1,
    "type_cupone": 2,
    "type_discount": 1,
    "discount": 15,
    "type_count": 2,
    "num_use": 200,
    "product_selected": [],
    "categorie_selected": [{ "id": 1 }],
    "brand_selected": []
  }'
{ "message": 200, "id": 6 }

Get Coupon

GET /api/admin/cupones/{id}
Path parameters
id
integer
required
Coupon ID.
Response
cupone
object
Full coupon resource (via CuponeResource) including id, code, type_discount, discount, type_count, num_use, type_cupone, state, created_at, and expanded products, categories, and brands arrays with resolved entity data and id_aux pivot IDs.
{
  "cupone": {
    "id": 6,
    "code": "TECH15",
    "type_discount": 1,
    "discount": 15,
    "type_count": 2,
    "num_use": 200,
    "type_cupone": 2,
    "state": 1,
    "created_at": "2024-06-01 09:00 AM",
    "products": [],
    "categories": [
      {
        "id": 1,
        "name": "Electronics",
        "imagen": null,
        "id_aux": 3
      }
    ],
    "brands": []
  }
}

Update Coupon

PUT /api/admin/cupones/{id}
Path parameters
id
integer
required
Coupon ID to update.
Body parameters — same as Create Coupon. On update, all existing cupone_products, cupone_categories, and cupone_brands pivot rows are deleted and recreated from the new *_selected arrays. If the new code already belongs to a different coupon, returns {"message": 403, "message_text": "El cupón ya existe"}. Response
{ "message": 200 }

Delete Coupon

DELETE /api/admin/cupones/{id}
Do not delete a coupon that has been applied to existing customer orders, as this may break order history records.
Path parameters
id
integer
required
Coupon ID to delete.
Response
{ "message": 200 }

Build docs developers (and LLMs) love