Skip to main content

Endpoint

method
string
default:"PUT"
PUT
endpoint
string
/api/category/
This endpoint requires authentication. Include a valid authorization token in the request.

Authentication

This endpoint is protected by the api.auth middleware. You must include a valid authorization token in the request headers.

Path Parameters

id
number
required
The ID of the category to update

Request Body

The request body must contain a json parameter with a JSON string containing the category data to update.
json
string
required
JSON string containing category data
name
string
required
The updated name of the category (required)

Validation Rules

  • name: Required field
The following fields are automatically excluded from the update and cannot be modified: id, created_at

Response

Returns a JSON object containing the update status and the updated data.

Success Response

code
number
HTTP status code (200 for success)
status
string
Response status (‘success’)
category
object
The updated category data (as submitted, not the full database record)
name
string
Updated category name

Error Response

code
number
HTTP status code (400 for validation error)
status
string
Response status (‘error’)
message
string
Error message describing what went wrong

Example Request

cURL
curl -X PUT http://your-domain.com/api/category/1 \
  -H "Authorization: Bearer YOUR_TOKEN_HERE" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d 'json={"name":"Updated Technology"}'

Example Responses

Success Response (200)

{
  "code": 200,
  "status": "success",
  "category": {
    "name": "Updated Technology"
  }
}

Empty Request Error (400)

{
  "code": 400,
  "status": "error",
  "message": "No has enviado ninguna categoria"
}

Implementation Details

This endpoint is defined in CategoryController.php:90. It:
  1. Receives data as a JSON string in the json parameter
  2. Validates that the name field is present (defined at line 99-101)
  3. Automatically removes id and created_at fields from the update data (lines 104-105)
  4. Updates the category using Laravel’s where()->update() method
  5. Returns the submitted parameters, not the full updated record from the database
The request expects data to be sent as a form parameter named json containing a JSON string, not as direct JSON in the request body. This is the same format used by the create endpoint.
The response returns the parameters that were submitted for update, not the complete category object from the database. To get the full updated category, make a subsequent GET request to /api/category/{id}.

Build docs developers (and LLMs) love