Back to Strategies API Documentation
Submit Purchase Endpoint
POST
.../api/v0/user/<user>/submit-purchase/<id-retailer>
This endpoint creates a new customer purchase and submits it to ArgoCD
Workflows for processing.
Authentication
This endpoint requires authentication using a Bearer token:
Authorization: Bearer <your_customer_token>
Parameters
URL Parameters
| Parameter |
Type |
Required |
Description |
| user |
String |
Yes |
User identifier |
| id-retailer |
String |
Yes |
Retailer identifier |
Request Body Parameters
| Parameter |
Type |
Required |
Description |
| purchase |
Array of Objects |
Yes |
Array of purchase objects. Each object must contain:
-
datetime (String, required): Date and time in
format "YYYY-MM-DD HH:MM"
-
purchase (Number, required): Energy purchase value
in MW
|
Request Format
The request must be sent as application/json:
POST /api/v0/user/<user>/submit-purchase?retailer_id=<retailer_id>
Authorization: Bearer <your_token>
Content-Type: application/json
{
"purchase": [
{
"datetime": "2025-11-11 00:15",
"purchase": 12.0
},
{
"datetime": "2025-11-11 00:30",
"purchase": 13.0
},
{
"datetime": "2025-11-11 00:45",
"purchase": 14.0
}
]
}
Response Format
Success Response (201 Created)
{
"id": "00000000-0000-0000-0000-000000000000",
"status": "pending",
"error": "",
"rows_uploaded": 96,
"created_at": "2024-01-15T14:30:00Z",
"message": "CustomerPurchase created successfully with ID: XX for user: XX and retailer: XX"
}
Example Usage
Here's an example of how to use this endpoint with curl:
curl -X POST \
"https://api.ravenwits.com/api/v0/user/trebolenergia/submit-purchase?retailer_id=123" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{
"purchase": [
{
"datetime": "2025-11-11 00:15",
"purchase": 12.0
},
{
"datetime": "2025-11-11 00:30",
"purchase": 13.0
}
]
}'
Error Responses
Authentication Error (401 Unauthorized)
{ "detail": "Authentication credentials were not provided." }
Validation Error (400 Bad Request)
Various validation errors can occur:
{ "error": "Missing required URL parameter "user"." }
or
{ "error": "Missing required field "purchase"." }
or
{ "error": "Field "purchase" must be an array of objects." }
or
{ "error": "Purchase item at index 0 is missing required field "datetime"."
}
or
{ "error": "Purchase item at index 0: invalid datetime format. Expected
"YYYY-MM-DD HH:MM" (e.g., "2024-01-15 14:30")." }
or
{ "error": "Purchase item at index 0: field "purchase" must be a number (in
MW unit)." }
Server Error (500 Internal Server Error)
{ "error": "Internal server error while creating purchase." }
Workflow Processing
After successfully creating the purchase, the system automatically submits a
workflow to ArgoCD Workflows for processing. If the workflow submission fails,
the purchase is still created but a warning is logged.