Endpoint: /wp-json/apicloud/v1/products/{id}
Description
This API endpoint retrieves a single product based on the provided product ID. It returns the details of the specified product, such as its ID, title, description, and custom field value for the cost. The endpoint expects the product ID as part of the URL.
URL
GET /wp-json/apicloud/v1/products/{id}
Where {id} is the unique identifier of the product you want to retrieve.
Methods
- GET: Retrieves the details of a single product identified by the product ID.
URL Parameters
- id: The ID of the product. This is a required parameter and must be a numeric value representing the product’s ID.
Response
The API will return a JSON object with the following structure:
jsonCopy{
"id": 123,
"name": "Product Name",
"description": "Product Description",
"cost": 199
}
Each product object contains:
- id: The unique ID of the product.
- name: The title of the product (post title).
- description: The excerpt of the product post, typically a short description of the product.
- cost: The custom field value
_api_service_cost(must be an integer).
Error Responses
- No Product ID Provided:
- Error Code:
no_product_id - Message:
Product ID is required - HTTP Status: 400 Bad Request
- This error occurs if the
idparameter is missing in the request.
{ "code": "no_product_id", "message": "Product ID is required", "data": { "status": 400 } } - Error Code:
- Product Not Found:
- Error Code:
product_not_found - Message:
Product not found - HTTP Status: 404 Not Found
- This error occurs if the product ID doesn’t correspond to an existing product or if the product is not of type
api_service.
{ "code": "product_not_found", "message": "Product not found", "data": { "status": 404 } } - Error Code:
Permissions
- The permission callback is set to
__return_true, meaning it allows access to anyone without authentication.Note: This can be adjusted to be more restrictive if needed (e.g., requiring an API key).