Endpoint: /wp-json/apicloud/v1/wallet/deduct
/wp-json/apicloud/v1/wallet/deductDescription
This API endpoint deducts points from the user’s wallet (using the mycred plugin). The number of points to deduct is provided in the request. It checks for the provided API key, validates the user, and ensures the user has enough points before deducting the specified amount. The endpoint also logs the usage of the service and returns a response containing the deducted points and the remaining balance.
URL
POST /wp-json/apicloud/v1/wallet/deduct
Methods
- POST: Deducts points from the user’s wallet based on the API key and request parameters.
Headers
- Authorization: A Bearer token containing the API key. The API key should be passed in the
Authorizationheader as follows:makefileCopyAuthorization: Bearer <API_KEY>Where<API_KEY>is the actual API key of the user.
Request Parameters
- coins_used (required): The number of points to deduct from the user’s wallet. It must be a positive integer.
- product_id(required): The name of the service for which the points are being used.
- message_content (required): The content or description of the message related to the service usage.
Request Example
bashCopyPOST /wp-json/apicloud/v1/wallet/deduct
Authorization: Bearer <API_KEY>
{
"coins_used": 50,
"product_id": "AI Service",
"message_content": "Service usage for AI model processing"
}
Response
The API will return a JSON object with the following structure:
jsonCopy{
"success": true,
"message": "Service usage deducted successfully!",
"product_id": "AI Service",
"deducted_points": 50,
"remaining_balance": 950
}
Where:
- success: Indicates that the deduction was successful.
- message: A confirmation message indicating that the service usage has been deducted.
- product_id: The name of the service for which the points were deducted.
- deducted_points: The number of points deducted from the wallet.
- remaining_balance: The remaining points in the user’s wallet after the deduction.
Error Responses
- Missing API Key:
- Error Code:
invalid_api_key - Message:
Missing API Key. - HTTP Status: 401 Unauthorized
- This error occurs if the
Authorizationheader is missing or invalid.
{ "code": "invalid_api_key", "message": "Missing API Key.", "data": { "status": 401 } } - Error Code:
- Invalid API Key:
- Error Code:
unauthorized - Message:
Invalid API Key. - HTTP Status: 403 Forbidden
- This error occurs if the API key does not correspond to any user.
{ "code": "unauthorized", "message": "Invalid API Key.", "data": { "status": 403 } } - Error Code:
- Missing Cost:
- Error Code:
missing_param - Message:
Missing Cost - HTTP Status: 401 Unauthorized
- This error occurs if the
coins_usedparameter is not provided.
{ "code": "missing_param", "message": "Missing Cost", "data": { "status": 401 } } - Error Code:
- Insufficient Points:
- Error Code:
insufficient_points - Message:
Not enough points. - HTTP Status: 402 Payment Required
- This error occurs if the user does not have enough points to cover the requested deduction.
{ "code": "insufficient_points", "message": "Not enough points.", "data": { "status": 402 } } - Error Code:
- Missing Product Id:
- Error Code:
missing_param - Message:
Product Id - HTTP Status: 401 Unauthorized
- This error occurs if the
product_idparameter is not provided.
- Error Code:
- Missing Message Content:
- Error Code:
missing_param - Message:
Message Content - HTTP Status: 401 Unauthorized
- This error occurs if the
message_contentparameter is not provided.
- Error Code:
Permissions
- The permission callback is set to
__return_true, meaning it allows access to anyone with a valid API key in theAuthorizationheader.