Solutech Engineering
Innovations/Suggested Products

API Endpoints

Complete API reference for the Suggested Products feature

API Endpoints

The Suggested Products feature provides a comprehensive set of REST API endpoints for managing and retrieving product suggestions. This section covers all available endpoints, request/response formats, and usage examples.

Base URLs

  • Eva Module: /eva/suggested-products
  • General API: /api/suggested-products
  • Web Interface: /eva/suggested-products (dashboard)

Authentication

All API endpoints require proper authentication. Include the following header in your requests:

Authorization: Bearer {your-access-token}
Content-Type: application/json
Accept: application/json

Eva Module Routes

GET /eva/suggested-products

Retrieve paginated suggested products report with advanced filtering capabilities.

Request Parameters

ParameterTypeRequiredDefaultDescription
pageintegerNo1Page number for pagination
per_pageintegerNo15Number of records per page
customer_idintegerNo-Filter by specific customer
region_idintegerNo-Filter by customer region
product_idintegerNo-Filter by specific product
category_idintegerNo-Filter by product category
statusstringNo-Filter by status (active/inactive)
start_datedateNo-Filter by analysis start date
end_datedateNo-Filter by analysis end date
searchstringNo-Search in customer/product names

Request Example

GET /eva/suggested-products?page=1&per_page=20&customer_id=123&status=active
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

Response Format

{
  "data": [
    {
      "id": 1,
      "customer_id": 123,
      "customer_name": "ABC Corporation",
      "product_set_id": "550e8400-e29b-41d4-a716-446655440000",
      "apriori_timestamp": "2024-10-15T10:30:00Z",
      "start_date": "2024-01-01",
      "end_date": "2024-10-15",
      "products": [
        {
          "product_id": 456,
          "product_name": "Product A",
          "product_code": "PROD-A-001",
          "priority": 1,
          "status": "active",
          "suggested_quantity": 10.5,
          "unit_price": 25.00,
          "total_value": 262.50
        },
        {
          "product_id": 789,
          "product_name": "Product B",
          "product_code": "PROD-B-002",
          "priority": 2,
          "status": "active",
          "suggested_quantity": 5.0,
          "unit_price": 15.00,
          "total_value": 75.00
        }
      ],
      "total_products": 2,
      "total_value": 337.50,
      "created_at": "2024-10-15T10:35:00Z",
      "updated_at": "2024-10-15T10:35:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "from": 1,
    "last_page": 5,
    "per_page": 20,
    "to": 20,
    "total": 95
  },
  "links": {
    "first": "/eva/suggested-products?page=1",
    "last": "/eva/suggested-products?page=5",
    "prev": null,
    "next": "/eva/suggested-products?page=2"
  }
}

POST /eva/suggested-products

Trigger generation of suggested products for a specific date range or customer.

Request Body

{
  "start_date": "2024-01-01",
  "end_date": "2024-10-15",
  "customer_ids": [123, 456, 789],  // Optional: specific customers
  "force_regenerate": false,        // Optional: force regeneration
  "algorithm_params": {             // Optional: custom parameters
    "support": 0.1,
    "confidence": 0.5
  }
}

Response Format

{
  "message": "Suggested products generation started successfully",
  "job_id": "job_uuid_123456",
  "status": "processing",
  "estimated_completion": "2024-10-15T11:00:00Z",
  "customers_to_process": 150,
  "data": {
    "start_date": "2024-01-01",
    "end_date": "2024-10-15",
    "algorithm_params": {
      "support": 0.1,
      "confidence": 0.5
    }
  }
}

GET /eva/download-suggested-products

Download suggested products report as an Excel file.

Request Parameters

ParameterTypeRequiredDescription
customer_idintegerNoFilter by specific customer
region_idintegerNoFilter by customer region
start_datedateNoFilter by analysis start date
end_datedateNoFilter by analysis end date
formatstringNoExport format (excel/csv)

Request Example

GET /eva/download-suggested-products?customer_id=123&format=excel
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

Response

Returns a downloadable Excel/CSV file with headers:

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Disposition: attachment; filename="suggested-products-2024-10-15.xlsx"

General API Routes

GET /suggested-products-from-recent-orders

Get real-time product suggestions based on recent customer orders.

Request Parameters

ParameterTypeRequiredDescription
shop_idintegerYesCustomer/shop identifier
limitintegerNoMaximum suggestions to return (default: 20)
order_cyclesintegerNoNumber of recent orders to analyze
filter_daysintegerNoFilter orders by days instead of cycles
include_substitutesbooleanNoInclude substitute products
include_pricingbooleanNoInclude customer-specific pricing

Request Example

GET /suggested-products-from-recent-orders?shop_id=123&limit=10&include_pricing=true
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...

Response Format

{
  "data": [
    {
      "product_id": 456,
      "product_code": "PROD-A-001",
      "product_desc": "Premium Widget A",
      "quantity": 5.0,
      "uom": "PCS",
      "selling_price": 25.00,
      "customer_id": 123,
      "priority": 1,
      "confidence_score": 0.85,
      "last_ordered": "2024-10-10",
      "average_quantity": 7.5,
      "order_frequency": "weekly",
      "substitute_products": [
        {
          "product_id": 457,
          "product_desc": "Standard Widget A",
          "selling_price": 20.00
        }
      ],
      "availability": {
        "in_stock": true,
        "stock_quantity": 100,
        "lead_time_days": 2
      }
    }
  ],
  "meta": {
    "customer_id": 123,
    "total_suggestions": 8,
    "analysis_period": {
      "start_date": "2024-09-15",
      "end_date": "2024-10-15",
      "orders_analyzed": 5
    },
    "algorithm": "recent_orders",
    "generated_at": "2024-10-15T14:30:00Z"
  }
}

Administrative Endpoints

GET /eva/suggested-products/status

Check the status of suggestion generation jobs.

Request Parameters

ParameterTypeRequiredDescription
job_idstringNoSpecific job ID to check

Response Format

{
  "jobs": [
    {
      "job_id": "job_uuid_123456",
      "status": "completed",
      "progress": 100,
      "customers_processed": 150,
      "customers_total": 150,
      "started_at": "2024-10-15T10:30:00Z",
      "completed_at": "2024-10-15T10:45:00Z",
      "duration_seconds": 900,
      "results": {
        "suggestions_generated": 1250,
        "customers_with_suggestions": 145,
        "errors": 0
      }
    }
  ]
}

GET /eva/suggested-products/errors

Retrieve error logs from suggestion generation processes.

Request Parameters

ParameterTypeRequiredDescription
pageintegerNoPage number for pagination
per_pageintegerNoRecords per page (max 100)
start_datedateNoFilter by error date

Response Format

{
  "data": [
    {
      "id": 1,
      "error_message": "Memory limit exceeded while processing customer 456",
      "stack_trace": "...",
      "created_at": "2024-10-15T10:35:00Z"
    }
  ],
  "meta": {
    "current_page": 1,
    "total": 5
  }
}

Webhook Endpoints

POST /webhook/suggested-products/completed

Webhook notification when suggestion generation is completed.

Payload Format

{
  "event": "suggestion_generation_completed",
  "job_id": "job_uuid_123456",
  "status": "completed",
  "timestamp": "2024-10-15T10:45:00Z",
  "data": {
    "customers_processed": 150,
    "suggestions_generated": 1250,
    "duration_seconds": 900,
    "start_date": "2024-01-01",
    "end_date": "2024-10-15"
  }
}

Error Handling

Standard Error Response

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "The given data was invalid.",
    "details": {
      "customer_id": ["The customer id field must be an integer."],
      "start_date": ["The start date field must be a valid date."]
    }
  },
  "timestamp": "2024-10-15T14:30:00Z",
  "request_id": "req_uuid_789012"
}

HTTP Status Codes

CodeDescriptionWhen It Occurs
200OKSuccessful request
201CreatedSuggestion generation started
400Bad RequestInvalid request parameters
401UnauthorizedMissing or invalid authentication
403ForbiddenInsufficient permissions
404Not FoundResource not found
422Unprocessable EntityValidation errors
429Too Many RequestsRate limiting applied
500Internal Server ErrorServer error
503Service UnavailableService temporarily unavailable

Rate Limiting

API endpoints are subject to rate limiting:

  • General Endpoints: 100 requests per minute per user
  • Generation Endpoints: 10 requests per hour per user
  • Download Endpoints: 20 requests per hour per user

Rate limit headers in response:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1634308800

SDK Examples

JavaScript/Node.js

const axios = require('axios');

class SuggestedProductsAPI {
  constructor(baseURL, token) {
    this.client = axios.create({
      baseURL,
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      }
    });
  }

  async getSuggestions(customerId, options = {}) {
    const params = { customer_id: customerId, ...options };
    const response = await this.client.get('/eva/suggested-products', { params });
    return response.data;
  }

  async getRecentOrderSuggestions(shopId, limit = 20) {
    const response = await this.client.get('/suggested-products-from-recent-orders', {
      params: { shop_id: shopId, limit }
    });
    return response.data;
  }

  async generateSuggestions(startDate, endDate, customerIds = null) {
    const data = { start_date: startDate, end_date: endDate };
    if (customerIds) data.customer_ids = customerIds;
    
    const response = await this.client.post('/eva/suggested-products', data);
    return response.data;
  }
}

PHP

class SuggestedProductsAPI {
    private $baseURL;
    private $token;
    
    public function __construct($baseURL, $token) {
        $this->baseURL = $baseURL;
        $this->token = $token;
    }
    
    public function getSuggestions($customerId, $options = []) {
        $params = array_merge(['customer_id' => $customerId], $options);
        $url = $this->baseURL . '/eva/suggested-products?' . http_build_query($params);
        
        return $this->makeRequest('GET', $url);
    }
    
    public function getRecentOrderSuggestions($shopId, $limit = 20) {
        $url = $this->baseURL . '/suggested-products-from-recent-orders?' . 
               http_build_query(['shop_id' => $shopId, 'limit' => $limit]);
        
        return $this->makeRequest('GET', $url);
    }
    
    private function makeRequest($method, $url, $data = null) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $this->token,
            'Content-Type: application/json'
        ]);
        
        if ($data) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        }
        
        $response = curl_exec($ch);
        curl_close($ch);
        
        return json_decode($response, true);
    }
}

This comprehensive API reference provides all the information needed to integrate with the Suggested Products feature effectively.