Products

Products are an essential part of LetsGo. On this page, we’ll dive into the different product endpoints you can use to manage products programmatically. We'll look at how to query, create, update, and delete products.

The product model

The product model contains all the information about the products.

Properties

  • Name
    _id
    Type
    ObjectId
    Description

    Unique identifier for the product.

  • Name
    name
    Type
    string
    Description

    The name for the product.

  • Name
    price
    Type
    int-32
    Description

    The price for the product.

  • Name
    description
    Type
    string
    Description

    The description for the product.

  • Name
    category
    Type
    string
    Description

    The category of the product.

  • Name
    image
    Type
    string
    Description

    The category of the product. Can only be from this array: [ "Star Wars", "Disney", "BIONICLE", "Harry Potter", "Batman", "Indiana Jones", "Ninjago", "Minecraft", "Technic", "Architecture", "Ideas", ];

  • Name
    stripePriceId
    Type
    string
    Description

    The price identifier of the product provided by Stripe .

  • Name
    stripeProductId
    Type
    string
    Description

    The product identifier of the product provided by Stripe .

  • Name
    created_at
    Type
    date
    Description

    Timestamp of when the contact was created.

  • Name
    updated_at
    Type
    date
    Description

    Timestamp of when the contact was updated.

  • Name
    __v
    Type
    int-32
    Description

    The version key of the product.


GET/products

List all products

This endpoint allows you to retrieve a paginated list of all your products. You can filter them by giving a page, limit, search, sort, and even categories.

Optional attributes

  • Name
    page
    Type
    int
    Description

    Page of the products returned. Default: 1

  • Name
    limit
    Type
    int
    Description

    Limit the number of products returned. Default: 0

  • Name
    search
    Type
    string
    Description

    Only show products that have this string in them. Default: ""

  • Name
    sort
    Type
    string
    Description

    Sort products by this field, if _asc or _desc is not given, asc is default. Default: "createdAt_desc"

  • Name
    category
    Type
    string
    Description

    Only show products within these categories, separeted by commas (","). Default: "All"

Response

{
  "total": 6,
  "page": 1,
  "limit": 3,
  "category": [
    "Star Wars"
  ],
  "products": [
    {
        "_id": "662eb3f04341bfa0b2d43ea3",
        "name": "LEGO Star Wars AT-AT™",
        "price": 35000,
        "description": "Keresse fel a webhelyet az aktuális árakkal és a rendelkezésre állással kapcsolatos információkért. A képek szerzői jogi védelem alatt állhatnak További információ",
        "category": "Star Wars",
        "image": "https://www.kockaaruhaz.hu/upload_files/products/75313-box3-v29.webp",
        "createdAt": "2024-04-28T20:39:13.896Z",
        "updatedAt": "2024-05-02T14:25:35.351Z"
    },
  // ...
  ]
}

POST/products

Create a product

ONLY ADMIN

This endpoint allows you to add a new products.

Required attributes

  • Name
    name
    Type
    string
    Description

    The name for the product.

  • Name
    price
    Type
    int-32
    Description

    The price for the product.

  • Name
    description
    Type
    string
    Description

    The description for the product.

  • Name
    category
    Type
    string
    Description

    The category for the product.

  • Name
    image
    Type
    url
    Description

    The image for the product.

Request body

POST
/products
{
  "name": "Cheapest Lego set ever",
  "price": 150,
  "description": "Cheapest set ever!",
  "category": "Star Wars",
  "image": "https://w7.pngwing.com/pngs/723/976/png-transparent-lego-star-wars-tatooine-toy-whirlwind-out-of-box-star-destroyer-droid-tusken-raiders.png"
}

Response

{
  "message": "Product created successfully",
  "product": {
    "_id": "663f91da8f4737036a41f3eb",
    "name": "Cheapest Lego set ever",
    "image": "https://w7.pngwing.com/pngs/723/976/png-transparent-lego-star-wars-tatooine-toy-whirlwind-out-of-box-star-destroyer-droid-tusken-raiders.png",
    "price": 150,
    "category": "Star Wars",
    "description": "Cheapest set ever!",
    "stripeProductId": "prod_Q5SzJracSTGeFY",
    "stripePriceId": "price_1PFI3zJrE0A1jpo1ADGiDs4n"
  }
}

GET/products/:id

Retrieve a product

This endpoint allows you to retrieve a product by providing the product id. Refer to the list at the top of this page to see which properties are included with product objects.

Response

{
  "_id": "6633e6535fec9229af0bab60",
  "name": "Millennium Falcon™",
  "price": 25000,
  "description": "Build the fastest ship in the galaxy and embark on epic adventures!",
  "category": "Star Wars",
 "image": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQuLW0jHbjnZSN8WhbqnBlRRCw1po0XHxBFlk88HygLdA&s",
  "createdAt": "2024-05-02T19:15:39.940Z",
  "updatedAt": "2024-05-02T19:15:39.940Z"
}

PUT/products/:id

Update a product

ONLY ADMIN

This endpoint allows you to perform an update on a conversation. Examples of updates are changing the name price or description.

Optional attributes

  • Name
    name
    Type
    string
    Description

    The name for the product.

  • Name
    price
    Type
    int-32
    Description

    The price for the product.

  • Name
    description
    Type
    string
    Description

    The description for the product.

  • Name
    category
    Type
    string
    Description

    The category for the product.

  • Name
    image
    Type
    url
    Description

    The image for the product.

Request body

PUT
/products/:id
{
  "name": "Most expensive Lego set ever",
  "price": 569000,
  "description": "You might not want to buy this",
  "category": "Disney",
  "image": "https://w7.pngwing.com/pngs/723/976/png-transparent-lego-star-wars-tatooine-toy-whirlwind-out-of-box-star-destroyer-droid-tusken-raiders.png"
}

Response

{
  "message": "Product updated successfully",
  "newProduct": {
    "name": "Most expensive Lego set ever",
    "price": 569000,
    "description": "You might not want to buy this",
    "category": "Disney",
    "image": "https://w7.pngwing.com/pngs/723/976/png-transparent-lego-star-wars-tatooine-toy-whirlwind-out-of-box-star-destroyer-droid-tusken-raiders.png"
  }
}

DELETE/product/:id

Delete a product

ONLY ADMIN

This endpoint allows you to delete your products in LetsGo. Note: This will permanently delete the product.

Required attributes

  • Name
    user_id
    Type
    ObjectId
    Description

    The _id of the user, given in token from the Authorization header.

Response

{
  "message": "Product deleted successfully"
}

Was this page helpful?