API 05: Update Product (PUT/PATCH)

Demonstration of updating an existing resource using the PUT or PATCH method.

🎯 Purpose for OutSystems Tutorial

This API completes the **CRUD** (Create, Read, **Update**, Delete) operations. It shows how to:

🔗 API Endpoint Details

Method:

PUT or PATCH

Endpoint URL Template:

https://api.ankitg.in/api/update-product.php?id={product_id}

Request Body:

Must be a **JSON Object** containing the fields you wish to update.

Example Request Body (to change price and stock of ID 103):

{
    "price": 9.99,
    "inStock": true,
    "description": "On sale now! Updated description."
}
            

💬 Expected Responses

A. Success Response (200 OK)

Returns a success message and the full updated product object.

{
    "status": "Success",
    "message": "Product ID 103 updated successfully.",
    "updatedProduct": {
        "id": 103,
        "name": "Low-Code T-Shirt",
        "price": 9.99,
        "inStock": true,
        "description": "On sale now! Updated description.",
        "lastUpdated": "2025-11-22 10:25:00"
    }
}
            

B. Failure Response (404 Not Found)

If the ID in the URL is not found.

{
    "error": "Resource not found",
    "message": "Product with ID 999 not found for update."
}
            

💡 Important for Tutorial Video!

To show the **impact** of this API call:
  1. In OutSystems, **read** product 103 using a **GET** (API 2). Show the current price ($19.99) and stock (False).
  2. Call this **PUT/PATCH** API to change the price to $9.99 and stock to True.
  3. **Read** product 103 again using the **GET** (API 2). Show that the price and stock have permanently changed in the API response!
▶️ Watch the Tutorial on Updating Data (PUT/PATCH)!