### Install Hiboutik API Library Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md Commands and setup instructions for installing the library via Composer or manual inclusion. ```sh composer require hiboutik/hiboutikapi ``` ```php require 'vendor/autoload.php'; ``` ```php require 'HiboutikAPI/src/Hiboutik/autoloader.php'; ``` -------------------------------- ### Use Legacy API v1 Methods with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Provides examples of using legacy API v1 methods in PHP for backward compatibility. It demonstrates how to initialize the API client for v1 and perform GET, POST, PUT, and DELETE requests using deprecated methods. ```php getHiboutik("/products/"); if ($hiboutik->errorCode === null) { print_r($result); } else { echo "Error code: " . $hiboutik->errorCode; } // Legacy POST request $result = $hiboutik->postHiboutik("products", [ "product_model" => "Legacy Product", "product_price" => "49.90" ]); // Legacy PUT request $result = $hiboutik->putHiboutik("sale/123", [ "sale_attribute" => "vendor_id", "new_value" => 5 ]); // Legacy DELETE request $result = $hiboutik->deleteHiboutik("/customer/456"); ``` -------------------------------- ### Install Hiboutik API Library Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Instructions for installing the library via Composer or manual file inclusion. This is the first step to enable the HiboutikAPI class in your PHP project. ```bash composer require hiboutik/hiboutikapi ``` ```php require 'vendor/autoload.php'; $hiboutik = new \Hiboutik\HiboutikAPI('my_account', 'user@example.com', 'api_key'); ``` ```php require 'HiboutikAPI/src/Hiboutik/autoloader.php'; $hiboutik = new \Hiboutik\HiboutikAPI('my_account', 'user@example.com', 'api_key'); ``` -------------------------------- ### Retrieve Data with GET Requests Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Perform GET requests to fetch products, stock levels, and sale details. The library handles response validation and provides access to pagination data. ```php $hiboutik = new \Hiboutik\HiboutikAPI($account, $user, $pass); $result = $hiboutik->get("/products/"); $stock = $hiboutik->get("/stock_available/warehouse_id/1"); $sale = $hiboutik->get("/sales/12345"); ``` -------------------------------- ### Perform API Operations Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md Examples of fetching product lists and creating new products using the Hiboutik API client. ```php $result = $hiboutik->get("/products/"); if ($hiboutik->request_ok) { print_r($result); } $result = $hiboutik->post("products", [ "product_model" => "My product", "product_price" => "99.90" ]); ``` -------------------------------- ### Handle Paginated API Responses with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Demonstrates how to fetch paginated data from the Hiboutik API using PHP. It shows how to retrieve the initial set of results, access pagination metadata (start, previous, current, next, last pages), and navigate to subsequent pages. ```php get("/customers/"); if ($hiboutik->request_ok) { print_r($result); // Get pagination information $pagination = $hiboutik->pagination(); if (!empty($pagination)) { print_r($pagination); /* Output structure: [ 'start' => [ 'number' => 1, 'link' => 'https://my_account.hiboutik.com/api/customers/?p=1', ], 'prev' => [ 'number' => 9, 'link' => 'https://my_account.hiboutik.com/api/customers/?p=9', ], 'current' => [ 'number' => 10, 'link' => 'https://my_account.hiboutik.com/api/customers/?p=10', ], 'next' => [ 'number' => 11, 'link' => 'https://my_account.hiboutik.com/api/customers/?p=11', ], 'last' => [ 'number' => 28, 'link' => 'https://my_account.hiboutik.com/api/customers/?p=28', ], ] */ // Navigate to next page if (isset($pagination['next'])) { $next_page = $hiboutik->get("/customers/?p=" . $pagination['next']['number']); } } } ``` -------------------------------- ### DELETE Request - Remove Resources with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This PHP snippet illustrates how to delete resources from Hiboutik using DELETE requests. It includes examples for deleting a single customer and a range of customers. Error handling is included to manage potential issues during deletion. ```php delete("/customer/123"); if ($hiboutik->request_ok) { print 'Customer deleted!'; } // Delete multiple customers in a range $customer_start = 1; $customer_end = 100; try { for ($i = $customer_start; $i <= $customer_end; $i++) { $del_result = $hiboutik->delete("/customer/$i"); print_r($del_result); } } catch (Exception $e) { echo $e->getMessage(); } ``` -------------------------------- ### Handle Pagination and Legacy Support Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md Retrieving pagination metadata and initializing the client for legacy API v1 support. ```php $pagination = $hiboutik->pagination(); $hiboutik = new \Hiboutik\HiboutikAPI(YOUR_HIBOUTIK_ACCOUNT, USER, KEY, '1'); ``` -------------------------------- ### Authenticate with Basic HTTP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Initialize the API client using account credentials. This method requires the account name, email, and API key to perform authenticated requests. ```php $hiboutik = new \Hiboutik\HiboutikAPI('my_account', 'user@example.com', 'your_api_key_here'); $result = $hiboutik->get("/brands/"); if ($hiboutik->request_ok) { print_r($result); } ``` -------------------------------- ### POST /products Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Creates a new product resource in the Hiboutik system. ```APIDOC ## POST /products ### Description Creates a new product in the inventory. ### Method POST ### Endpoint /products ### Request Body - **product_model** (string) - Required - Name of the product - **product_barcode** (string) - Required - Unique barcode - **product_price** (float) - Required - Selling price ### Request Example { "product_model": "My product", "product_barcode": "1234567890123", "product_price": "99.90" } ### Response #### Success Response (200) - **id** (integer) - The ID of the created product #### Response Example { "id": 123 } ``` -------------------------------- ### Authenticate with Hiboutik API Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md Demonstrates how to initialize the Hiboutik client using either Basic authentication or OAuth. ```php $hiboutik = new \Hiboutik\HiboutikAPI(YOUR_HIBOUTIK_ACCOUNT, USER, KEY); $hiboutik = new \Hiboutik\HiboutikAPI(YOUR_HIBOUTIK_ACCOUNT); $hiboutik->oauth(ACCESS_TOKEN); ``` -------------------------------- ### POST Request - Create Products with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This snippet demonstrates how to create new products in Hiboutik using a POST request. It requires the Hiboutik API client to be initialized with account credentials. The function takes product details as an associative array and returns the result of the API call. ```php post("products", [ "product_model" => "My product", "product_barcode" => "1234567890123", "product_brand" => "2", "product_supplier" => "2", "product_price" => "99.90", "product_discount_price" => "89.90", "product_category" => 5, "product_size_type" => 0, "product_stock_management" => 0, "product_supplier_reference" => "SUP-REF-001", "product_vat" => 0 ]); if ($hiboutik->request_ok) { print 'Product created!'; print_r($result); } else { if (isset($result['details']['error_description'])) { print $result['details']['error_description']; } else { print $result['error_description']; } } ``` -------------------------------- ### File Upload - Product Images with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This code demonstrates uploading product images to Hiboutik via POST requests with file attachments. It shows how to upload a thumbnail, and also how to specify framing options and resolution for high-quality images. The function requires the product ID and the image file path. ```php post("/products_images/$product_id/", null, [ 'image' => [ [ 'file' => '/path/to/image.jpg' ] ] ]); if ($hiboutik->request_ok) { print_r($result); } else { print 'An error has occurred'; if (isset($result['details']['error_description'])) { print ': ' . $result['details']['error_description']; } else { print ': ' . $result['error_description']; } } // Upload with framing options and 1000x1000 resolution $result = $hiboutik->post("/products_images/$product_id/", ['framing_type' => 'frame'], [ 'image' => [ [ 'file' => '/path/to/image.jpg', 'type' => 'image/jpeg' ] ] ]); // Upload high resolution image (1000x1000) $result = $hiboutik->post("/products_images_1000x1000/$product_id/", [ 'framing_type' => 'frame', 'image_id' => 1 ], [ 'image' => [ [ 'file' => '/path/to/image.jpg' ] ] ]); ``` -------------------------------- ### POST /products_images/{id} Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Uploads images for a specific product. ```APIDOC ## POST /products_images/{id} ### Description Uploads a thumbnail or high-resolution image for a product. ### Method POST ### Endpoint /products_images/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The product ID ### Request Body - **image** (file) - Required - The image file to upload - **framing_type** (string) - Optional - Framing style ### Response #### Success Response (200) - **image_id** (integer) - ID of the uploaded image ``` -------------------------------- ### Authenticate with OAuth Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Initialize the API client using an OAuth access token. This provides a more secure, token-based authorization method for API interactions. ```php $hiboutik = new \Hiboutik\HiboutikAPI('my_account'); $hiboutik->oauth('2c88e36c68f87a0186r88d370cbb2b4e824f270f'); $result = $hiboutik->get("/brands/"); ``` -------------------------------- ### Product Creation API Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md This endpoint allows you to create a new product in your Hiboutik account by providing product details. ```APIDOC ## POST /products ### Description Creates a new product in your account. ### Method POST ### Endpoint /products ### Parameters #### Request Body - **product_model** (string) - Required - The name or model of the product. - **product_barcode** (string) - Optional - The barcode of the product. - **product_brand** (string) - Optional - The ID of the product brand. - **product_supplier** (string) - Optional - The ID of the product supplier. - **product_price** (string) - Required - The selling price of the product. - **product_discount_price** (string) - Optional - The discounted price of the product. - **product_category** (integer) - Optional - The ID of the product category. - **product_size_type** (integer) - Optional - The size type of the product (e.g., 0 for none). - **product_stock_management** (integer) - Optional - Whether stock management is enabled (e.g., 0 for disabled). - **product_supplier_reference** (string) - Optional - The supplier's reference for the product. - **product_vat** (integer) - Optional - The VAT rate ID for the product. ### Request Example ```php $result = $hiboutik->post("products", [ "product_model" => "My new product", "product_barcode" => "1234567890", "product_brand" => "2", "product_supplier" => "2", "product_price" => "19.99", "product_discount_price" => "15.99", "product_category" => 5, "product_size_type" => 0, "product_stock_management" => 0, "product_supplier_reference" => "REF001", "product_vat" => 0 ]); if ($hiboutik->request_ok) { print 'Product created!'; } else { if (isset($result['details']['error_description'])) { print $result['details']['error_description']; } else { print $result['error_description']; } } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Product created successfully." } ``` ``` -------------------------------- ### Error Handling with Hiboutik API Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Demonstrates how to implement comprehensive error handling for API requests, including network failures and validation issues. It shows how to check the `request_ok` property and parse error responses. ```APIDOC ## GET /products/ ### Description Retrieves a list of products from the Hiboutik API. This example demonstrates how to handle potential errors during the API call. ### Method GET ### Endpoint /products/ ### Parameters None ### Request Example ```php get("/products/"); // ... rest of the code } catch (Exception $e) { echo "Exception: " . $e->getMessage() . "\n"; } ``` ### Response #### Success Response (200) - **array** - A list of product objects. #### Response Example ```json [ { "product_model": "Example Product Model", "product_price": 19.99 // ... other product details } ] ``` #### Error Response - **string** `error` - The type of error. - **integer** `code` - The error code. - **string** `error_description` - A description of the error. - **object** `details` - Contains additional error information. - **string** `details.error_description` - Detailed error message. - **integer** `details.http_code` - The HTTP status code of the error response. #### Error Response Example ```json { "error": "invalid_request", "code": 99, "error_description": "Unknown error", "details": { "http_code": 404, "response": null } } ``` ``` -------------------------------- ### Product Listing API Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md This endpoint retrieves a list of all active products associated with your Hiboutik account. ```APIDOC ## GET /products/ ### Description Retrieves a list of all active products. ### Method GET ### Endpoint /products/ ### Parameters #### Query Parameters - **page** (integer) - Optional - The page number to retrieve. - **limit** (integer) - Optional - The number of items per page. ### Request Example ```php $result = $hiboutik->get("/products/"); if ($hiboutik->request_ok) { print_r($result); } else { if (isset($result['details']['error_description'])) { print $result['details']['error_description']; } else { print $result['error_description']; } } ``` ### Response #### Success Response (200) - **products** (array) - A list of product objects. - **pagination** (object) - Pagination details. #### Response Example ```json { "products": [ { "product_id": "1", "product_model": "Sample Product", "product_price": "10.00" } ], "pagination": { "current_page": 1, "total_pages": 5, "total_items": 50 } } ``` ``` -------------------------------- ### Configure Hiboutik API Return Format with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Explains how to configure the Hiboutik API client in PHP to return results as either associative arrays (default) or objects. This allows developers to choose the data structure that best fits their coding style. ```php return_array = true; $result = $hiboutik->get("/products/"); // Access as: $result[0]['product_model'] // Return as objects instead $hiboutik->return_array = false; $result = $hiboutik->get("/products/"); // Access as: $result[0]->product_model ``` -------------------------------- ### PUT Request - Update Resources with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This code shows how to update existing resources in Hiboutik using PUT requests. It covers updating a sale's vendor and a line item's loyalty points. The function requires the resource ID and the data to be updated, returning the API response. ```php "vendor_id", "new_value" => 5, ]; $result = $hiboutik->put("/sale/12345", $data); if ($hiboutik->request_ok) { print 'Sale vendor updated!'; } else { print 'Error: ' . $result['error_description']; } // Update line item points (loyalty program) $data = [ "line_item_attribute" => "points", "new_value" => 100, ]; $update_result = $hiboutik->put("/sale_line_item/67890", $data); if ($hiboutik->request_ok) { print 'Points updated!'; } ``` -------------------------------- ### Access API Response Headers and Status with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Shows how to retrieve HTTP response headers and detailed status information from Hiboutik API requests using PHP. This is useful for debugging, logging, and understanding the specifics of an API call. ```php get("/products/"); // Check if request was successful if ($hiboutik->request_ok) { print "Request successful!\n"; } // Get all response headers $headers = $hiboutik->headers(); print_r($headers); // Get a specific header field $content_type = $hiboutik->headers('Content-Type'); echo "Content-Type: $content_type\n"; // Get complete status information (curl info) $status = $hiboutik->getStatus(); print_r($status); /* Contains: http_code, total_time, namelookup_time, connect_time, content_type, url, etc. */ ``` -------------------------------- ### Handle Hiboutik API Errors in PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This snippet demonstrates how to implement comprehensive error handling when interacting with the Hiboutik API using PHP. It covers managing API-returned errors, network failures, and validation issues by checking the `request_ok` property and catching exceptions. ```php get("/products/"); if ($hiboutik->request_ok) { // Success - process results foreach ($result as $product) { echo $product['product_model'] . "\n"; } } else { // API returned an error if (isset($result['error'])) { echo "Error: " . $result['error'] . "\n"; echo "Code: " . $result['code'] . "\n"; echo "Description: " . $result['error_description'] . "\n"; // Check for detailed error information if (isset($result['details']['error_description'])) { echo "Details: " . $result['details']['error_description'] . "\n"; } if (isset($result['details']['http_code'])) { echo "HTTP Code: " . $result['details']['http_code'] . "\n"; } } } } catch (Exception $e) { // Handle exceptions (network errors, etc.) echo "Exception: " . $e->getMessage() . "\n"; } // Example error response structure: /* [ 'error' => 'invalid_request', 'code' => 99, 'error_description' => 'Unknown error', 'details' => [ 'http_code' => 404, 'response' => null ] ] */ ``` -------------------------------- ### Handle Hiboutik Webhook Callbacks in PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt This PHP script demonstrates how to create a callback handler for Hiboutik webhooks. It validates incoming POST data, retrieves sale details, processes line items to calculate loyalty points, and updates the sale via the API. It also includes basic error handling and returns a JSON response. ```php get("/sales/$sale_id"); if ($hiboutik->request_ok) { $line_items = $sale[0]['line_items']; // Process each line item (e.g., calculate loyalty points) foreach ($line_items as $item) { $line_item_id = $item['line_item_id']; $quantity = $item['quantity']; $price = $item['product_price']; // Calculate points (1 euro = 1 point) $points = intval($quantity * $price); // Update points $hiboutik->put("/sale_line_item/$line_item_id", [ "line_item_attribute" => "points", "new_value" => $points, ]); } // Return success response to Hiboutik header('Content-type: application/json; charset=utf-8'); echo json_encode([ "alerte" => '
Points applied successfully
' ]); } } catch (Exception $e) { error_log($e->getMessage(), 0); http_response_code(500); echo json_encode(["error" => $e->getMessage()]); } ``` -------------------------------- ### Webhook Callback Handler for Sales Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Provides a handler for Hiboutik webhooks, specifically for sale closure events. It demonstrates how to validate incoming data, retrieve sale details, process line items, and update information. ```APIDOC ## POST /sales/{sale_id} ### Description This endpoint is designed to be called by Hiboutik webhooks. It processes sale data, calculates loyalty points based on line items, and updates the sale line item attributes. ### Method POST ### Endpoint This is a webhook endpoint, the actual path will be configured in your Hiboutik account settings. ### Parameters #### Request Body (from Hiboutik) - **sale_id** (string) - Required - The ID of the sale that triggered the webhook. - **user_id** (string) - Optional - The ID of the user associated with the sale. - **vendor_id** (string) - Optional - The ID of the vendor associated with the sale. ### Request Example (Webhook Payload) ```json { "sale_id": "12345", "user_id": "user_abc", "vendor_id": "vendor_xyz" } ``` ### Response #### Success Response (200) Returns a JSON object indicating success. #### Response Example ```json { "alerte": "
Points applied successfully
" } ``` #### Error Response (500) Returns a JSON object with an error message if processing fails. #### Error Response Example ```json { "error": "Please provide a valid sale_id" } ``` ``` -------------------------------- ### Pagination Information API Source: https://github.com/hiboutik/hiboutikapi/blob/master/README.md This endpoint retrieves pagination information, which is useful for navigating through large datasets returned by the API. ```APIDOC ## GET /pagination ### Description Retrieves pagination details for the API. ### Method GET ### Endpoint /pagination ### Parameters None ### Request Example ```php $pagination = $hiboutik->pagination(); print_r($pagination); ``` ### Response #### Success Response (200) - **current_page** (integer) - The current page number. - **total_pages** (integer) - The total number of pages available. - **total_items** (integer) - The total number of items across all pages. #### Response Example ```json { "current_page": 1, "total_pages": 10, "total_items": 100 } ``` ``` -------------------------------- ### Repeat Last Hiboutik API Request with PHP Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Illustrates how to use the `repeat` method in the Hiboutik API client for PHP. This function allows re-executing the most recent API request, which is useful for retrying operations or refreshing data without re-specifying parameters. ```php get("/products/"); // Later, repeat the same request $refreshed_result = $hiboutik->repeat(); if ($hiboutik->request_ok) { print_r($refreshed_result); } ``` -------------------------------- ### DELETE /resource/{id} Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Removes a specific resource from the system. ```APIDOC ## DELETE /resource/{id} ### Description Deletes a resource by its ID. ### Method DELETE ### Endpoint /{resource}/{id} ### Parameters #### Path Parameters - **resource** (string) - Required - The type of resource to delete - **id** (integer) - Required - The ID of the resource ### Response #### Success Response (200) - **message** (string) - Confirmation of deletion ``` -------------------------------- ### PUT /resource/{id} Source: https://context7.com/hiboutik/hiboutikapi/llms.txt Updates existing resources such as sales or line items using a specific ID. ```APIDOC ## PUT /resource/{id} ### Description Updates specific attributes of an existing resource. ### Method PUT ### Endpoint /{resource}/{id} ### Parameters #### Path Parameters - **resource** (string) - Required - The type of resource (e.g., sale, sale_line_item) - **id** (integer) - Required - The unique identifier of the resource ### Request Body - **attribute** (string) - Required - The field to update - **new_value** (mixed) - Required - The new value to set ### Request Example { "sale_attribute": "vendor_id", "new_value": 5 } ### Response #### Success Response (200) - **status** (string) - Confirmation of update ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.