### Install Boxtal PHP Library Source: https://github.com/boxtal/php-library/blob/master/README.md Use Composer to add the library to your project dependencies. ```bash $ composer require boxtale/php-library ``` -------------------------------- ### Configure Proforma Invoice and Create International Order Source: https://context7.com/boxtal/php-library/llms.txt Use setProforma to define customs items before calling makeOrder for international shipments. Array keys for proforma items must start at 1. ```php array( 'description_en' => 'Cotton T-Shirts', 'description_fr' => 'T-shirts en coton', 'origine' => 'FR', // Country of origin (ISO code) or 'EEE' for European Economic Area 'number' => 5, // Quantity 'value' => 25.00 // Unit value in EUR ), 2 => array( 'description_en' => 'Leather Belt', 'description_fr' => 'Ceinture en cuir', 'origine' => 'IT', 'number' => 2, 'value' => 45.00 ) ); $lib->setProforma($proformaItems); // International shipment to Australia $from = array( 'country' => 'FR', 'zipcode' => '75002', 'city' => 'Paris', 'address' => '15, rue Marsollier', 'type' => 'company', 'title' => 'M', 'firstname' => 'John', 'lastname' => 'Doe', 'societe' => 'My Company', 'email' => 'john@company.com', 'phone' => '0606060606' ); $to = array( 'country' => 'AU', 'state' => 'NSW', 'zipcode' => '2000', 'city' => 'Sydney', 'address' => '123 King Street', 'type' => 'individual', 'title' => 'M', 'firstname' => 'Jane', 'lastname' => 'Smith', 'email' => 'jane@example.com', 'phone' => '+61412345678' ); $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array('poids' => 2, 'longueur' => 30, 'largeur' => 20, 'hauteur' => 15) ) ); $additionalParams = array( 'collection_date' => date('Y-m-d'), 'content_code' => 30110, 'colis.valeur' => '215.00', 'colis.description' => 'Clothing items', 'reason' => 'sale', // Shipment reason: sale, repair, return, gift, sample, personal, documents, other 'operator' => 'UPSE', 'service' => 'ExpressSaver' ); $orderPassed = $lib->makeOrder($from, $to, $parcels, $additionalParams); if ($orderPassed && !empty($lib->order['proforma'])) { echo "Proforma Invoice URL: " . $lib->order['proforma'] . "\n"; } ``` -------------------------------- ### Get Partnership Status with User Class Source: https://context7.com/boxtal/php-library/llms.txt Retrieves the partnership status associated with the authenticated user's account using the User class. Checks for the presence of a partnership code. ```php getPartnership(); if (!$lib->curl_error && !$lib->resp_error) { if ($lib->partnership) { echo "Partnership Code: " . $lib->partnership . "\n"; } else { echo "No partnership associated with this account\n"; } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } ``` -------------------------------- ### Get Order Information and Documents with OrderStatus Class Source: https://context7.com/boxtal/php-library/llms.txt Retrieves order status, label availability, and shipping documents like waybills using the OrderStatus class. Requires order references and specifies document type for downloads. ```php getOrderInformations($orderReference); if (!$lib->curl_error && !$lib->resp_error) { echo "=== Order Status ===\n"; echo "EMC Reference: " . $lib->order_info['emcRef'] . "\n"; echo "Carrier Reference: " . $lib->order_info['opeRef'] . "\n"; echo "Status: " . $lib->order_info['state'] . "\n"; echo "Label Available: " . ($lib->order_info['labelAvailable'] ? 'Yes' : 'No') . "\n"; if ($lib->order_info['labelAvailable']) { echo "Label URL: " . $lib->order_info['labelUrl'] . "\n"; // Individual label URLs foreach ($lib->order_info['labels'] as $index => $labelUrl) { echo "Label " . ($index + 1) . ": " . $labelUrl . "\n"; } } // Available documents if (!empty($lib->order_info['documents'])) { echo "\nDocuments:\n"; foreach ($lib->order_info['documents'] as $type => $url) { echo " {$type}: {$url}\n"; } } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } // Download shipping documents (waybill) $lib2 = new OrderStatus(); $references = array('1234567890ABCD123456', '1234567890EFGH789012'); $lib2->getOrderDocuments($references, 'waybill'); // 'waybill' or 'delivery_waybill' if ($lib2->document) { // Save PDF document file_put_contents('waybill.pdf', $lib2->document); echo "Waybill saved to waybill.pdf\n"; } ``` -------------------------------- ### Get List of Countries with Boxtal PHP Library Source: https://github.com/boxtal/php-library/blob/master/README.md Fetch the list of supported countries for shipping. This is essential for using the correct ISO codes in your order requests, as the API requires them for specifying shipment origins and destinations. ```php $lib = new $lib->getCountries(); // The countries list is available on the array : $lib->countries if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->countries); } else { handle_errors($lib); } ``` -------------------------------- ### Get Available Content Types with Boxtal PHP Library Source: https://github.com/boxtal/php-library/blob/master/README.md Retrieve a list of available content types for shipping. This is useful for understanding the nature of items that can be shipped and for populating the 'content_code' parameter in order requests. ```php require __DIR__ . '/vendor/autoload.php'; $lib = new $lib->getCategories(); // load all content categories $lib->getContents(); // load all content types // The content categories list is available on the array : $lib->categories // The content types list is available on the array : $lib->contents if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->categories); print_r($lib->contents); } else { handle_errors($lib); } ``` -------------------------------- ### Get Shipping Quotations Source: https://context7.com/boxtal/php-library/llms.txt Retrieve shipping quotes by providing origin, destination, parcel details, and additional parameters. This method returns an array of shipping offers, including pricing and delivery information. ```php 'FR', 'zipcode' => '75002', 'city' => 'Paris', 'address' => '15 rue Marsollier', 'type' => 'company' ); // Recipient address (destination) $to = array( 'country' => 'FR', 'zipcode' => '33000', 'city' => 'Bordeaux', 'address' => '24, rue des Ayres', 'type' => 'individual' ); // Parcel dimensions (weight in kg, dimensions in cm) $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array( 'poids' => 1, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8 ) ) ); // Additional parameters $additionalParams = array( 'collection_date' => date('Y-m-d'), 'delay' => 'aucun', 'content_code' => 10120, 'colis.valeur' => '42.655' ); $lib = new Quotation(); $lib->getQuotation($from, $to, $parcels, $additionalParams); if (!$lib->curl_error && !$lib->resp_error) { foreach ($lib->offers as $offer) { echo "Carrier: " . $offer['operator']['label'] . "\n"; echo "Service: " . $offer['service']['label'] . "\n"; echo "Price: " . $offer['price']['tax-inclusive'] . " " . $offer['price']['currency'] . "\n"; echo "Collection: " . $offer['collection']['date'] . " (" . $offer['collection']['type'] . ")\n"; echo "Delivery: " . $offer['delivery']['date'] . " (" . $offer['delivery']['type'] . ")\n"; echo "---\n"; } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } /* Sample offer structure: Array( 'mode' => 'COM', 'operator' => array('code' => 'CHRP', 'label' => 'Chronopost', 'logo' => 'url'), 'service' => array('code' => 'Chrono13', 'label' => 'Chronopost 13h'), 'price' => array('currency' => 'EUR', 'tax-exclusive' => '12.50', 'tax-inclusive' => '15.00'), 'collection' => array('type' => 'HOME', 'date' => '2024-01-15', 'label' => 'Home pickup'), 'delivery' => array('type' => 'HOME', 'date' => '2024-01-16', 'label' => 'Home delivery'), 'characteristics' => array('Next day delivery', 'Tracking included'), 'mandatory' => array('shipper.phone' => array(...), ...), 'hasInsurance' => true ) */ ``` -------------------------------- ### Get Details for a Specific Parcel Point Source: https://context7.com/boxtal/php-library/llms.txt Use the ParcelPoint class to retrieve detailed information about a specific pickup or dropoff point using its code and country. Handles both pickup and dropoff point types. ```php getParcelPoint('pickup_point', 'MONR-087106', 'FR'); if (!$lib->curl_error && !$lib->resp_error) { foreach ($lib->points['pickup_point'] as $point) { echo "=== Pickup Point Details ===\n"; echo "Code: {$point['code']}\n"; echo "Name: {$point['name']}\n"; echo "Address: {$point['address']}\n"; echo "City: {$point['zipcode']} {$point['city']}\n"; echo "Country: {$point['country']}\n"; echo "Phone: {$point['phone']}\n"; echo "GPS: {$point['latitude']}, {$point['longitude']}\n"; echo "Description: {$point['description']}\n"; echo "\nOpening Hours:\n"; foreach ($point['schedule'] as $day) { echo " {$day['weekday']}: "; if ($day['open_am'] || $day['open_pm']) { if ($day['open_am']) echo "{$day['open_am']}-{$day['close_am']} "; if ($day['open_pm']) echo "{$day['open_pm']}-{$day['close_pm']}"; } else { echo "Closed"; } echo "\n"; } } } else { foreach ($lib->resp_errors_list as $error) { echo "Error [{$error['code']}]: {$error['message']}\n"; } } // Get dropoff point details $lib2 = new ParcelPoint(); $lib2->getParcelPoint('dropoff_point', 'CHRP-POST', 'FR'); if (!$lib2->curl_error && !$lib2->resp_error) { foreach ($lib2->points['dropoff_point'] as $point) { echo "\n=== Dropoff Point ===\n"; echo "Name: {$point['name']}\n"; echo "Address: {$point['address']}, {$point['city']}\n"; } } ``` -------------------------------- ### Configure API Credentials Source: https://github.com/boxtal/php-library/blob/master/README.md Define the environment mode and authentication credentials in the configuration file. ```php define("EMC_MODE", "test"); if (EMC_MODE == "prod") { define("EMC_USER", "myLogin"); define("EMC_PASS", "myPassword"); } else { define("EMC_USER", "myLogin"); define("EMC_PASS", "myPassword"); } ``` -------------------------------- ### Configure API Credentials and Environment Source: https://context7.com/boxtal/php-library/llms.txt Set up your API credentials and choose between 'test' or 'production' environments before making API calls. This configuration is essential for authenticating with the Boxtal API. ```php getCountries(); if (!$lib->curl_error && !$lib->resp_error) { // List all available countries echo "=== Available Countries ===\n"; foreach ($lib->countries as $code => $country) { $euStatus = $country->is_ue ? '[EU]' : ''; echo "[{$code}] {$country->label} {$euStatus}\n"; // List states/regions if available if (!empty($country->states)) { foreach ($country->states as $state) { echo " - [{$state->code}] {$state->label}\n"; } } } // Get specific country with related territories $lib->getCountry('FR'); echo "\n=== France and territories ===\n"; foreach ($lib->country as $territory) { echo "[{$territory->code}] {$territory->label}\n"; } // Get US with all states $lib->getCountry('US'); if (!empty($lib->country)) { echo "\n=== United States ===\n"; $us = $lib->country[0]; echo "Country: {$us->label}\n"; echo "States:\n"; foreach ($us->states as $state) { echo " [{$state->code}] {$state->label}\n"; } } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } ``` -------------------------------- ### Place a shipping order with makeOrder Source: https://context7.com/boxtal/php-library/llms.txt Requires complete shipper and recipient details, parcel information, and carrier-specific parameters to successfully place an order. ```php 'FR', 'zipcode' => '75002', 'city' => 'Paris', 'address' => '15, rue Marsollier', 'type' => 'company', 'title' => 'M', // 'M' (sir) or 'Mme' (madam) 'firstname' => 'Jon', 'lastname' => 'Snow', 'societe' => 'Boxtale', // Company name 'email' => 'jsnow@boxtale.com', 'phone' => '0606060606', 'infos' => 'Building A, 2nd floor' ); // Complete recipient address $to = array( 'country' => 'FR', 'zipcode' => '13002', 'city' => 'Marseille', 'address' => '1, rue Chape', 'type' => 'individual', 'title' => 'Mme', 'firstname' => 'Jane', 'lastname' => 'Doe', 'email' => 'jdoe@example.com', 'phone' => '0707070707', 'infos' => 'Door code: 1234' ); // Parcel information $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array( 'poids' => 5, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8 ) ) ); // Order parameters (including carrier-specific mandatory fields from quotation) $additionalParams = array( 'collection_date' => date('Y-m-d'), 'delay' => 'aucun', 'content_code' => 40110, 'colis.description' => 'Books and magazines', 'colis.valeur' => '42.655', 'assurance.selection' => false, 'url_push' => 'https://www.my-website.com/webhook/shipping', 'depot.pointrelais' => 'MONR-000515', // Dropoff point (or '{OPERATOR}-POST' for home) 'retrait.pointrelais' => 'MONR-087106', // Pickup point (or '{OPERATOR}-POST' for home) 'operator' => 'MONR', // Carrier code from quotation 'service' => 'CpourToi' // Service code from quotation ); $lib = new Quotation(); $orderPassed = $lib->makeOrder($from, $to, $parcels, $additionalParams); if (!$lib->curl_error && !$lib->resp_error) { if ($orderPassed) { echo "Order placed successfully!\n"; echo "Reference: " . $lib->order['ref'] . "\n"; echo "Date: " . $lib->order['date'] . "\n"; // Access shipping labels if (!empty($lib->order['labels'])) { foreach ($lib->order['labels'] as $label) { echo "Label URL: " . $label . "\n"; } } } else { echo "Order was refused\n"; } } else { foreach ($lib->resp_errors_list as $error) { echo "Error [{$error['code']}]: {$error['message']}\n"; } } ``` -------------------------------- ### Make an Order with Boxtal PHP Library Source: https://github.com/boxtal/php-library/blob/master/README.md Use this snippet to create a new order. Ensure all required sender, recipient, and parcel details are provided, along with any necessary additional parameters like pickup times or content descriptions for international shipments. ```php require __DIR__ . '/vendor/autoload.php'; // shipper address $from = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '75002', 'ville' => 'Paris', 'type' => 'entreprise', // accepted values are "particulier" or "entreprise" 'adresse' => '15, rue Marsollier', 'civilite' => 'M', // accepted values are "M" (sir) or "Mme" (madam) 'prenom' => 'John', 'nom' => 'Snow', 'societe' => 'Boxtale', 'email' => 'jsnow@boxtale.com', 'tel' => '0606060606', 'infos' => 'Some informations about this address' ); // Recipient address $to = array( 'pays' => 'FR', // must be an ISO code, set get_country example on how to get codes 'code_postal' => '13002', 'ville' => 'Marseille', 'type' => 'particulier', // accepted values are "particulier" or "entreprise" 'adresse' => '1, rue Chape', 'civilite' => 'Mme', // accepted values are "M" (sir) or "Mme" (madam) 'prenom' => 'Jane', 'nom' => 'Doe', 'email' => 'jdoe@boxtale.com', 'tel' => '0606060606', 'infos' => 'Some informations about this address' ); /* Parcel information */ $parcels = array( 'type' => 'colis', 'dimensions' => array( 1 => array( 'poids' => 5, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8 ) ) ); $additionalParams = array( 'collecte' => date('Y-m-d'), 'delai' => "aucun", 'assurance.selection' => false, // whether you want an extra insurance or not 'url_push' => 'www.my-website.com/push.php&order=', 'content_code' => 40110, 'colis.description' => "Tissus, vĂȘtements neufs", 'valeur' => "42.655", 'depot.pointrelais' => 'CHRP-POST', 'operator' => 'CHRP', 'service' => 'Chrono18' ); // Prepare and execute the request $lib = new $orderPassed = $lib->makeOrder($from, $to, $parcels, $additionalParams); if (!$lib->curl_error && !$lib->resp_error) { print_r($lib->order); } else { handle_errors($lib); } ``` -------------------------------- ### makeOrder Method Source: https://context7.com/boxtal/php-library/llms.txt Places a shipping order with a carrier using the provided address, parcel, and service details. ```APIDOC ## POST makeOrder ### Description The `makeOrder` method places an actual shipping order with a carrier. It requires complete shipper and recipient details including contact information, and returns an order reference number upon success. ### Request Body - **from** (array) - Required - Complete shipper address with contact details (country, zipcode, city, address, type, title, firstname, lastname, societe, email, phone, infos) - **to** (array) - Required - Complete recipient address (country, zipcode, city, address, type, title, firstname, lastname, email, phone, infos) - **parcels** (array) - Required - Parcel information including type and dimensions (poids, longueur, largeur, hauteur) - **additionalParams** (array) - Required - Order parameters including collection_date, delay, content_code, colis.description, colis.valeur, assurance.selection, url_push, depot.pointrelais, retrait.pointrelais, operator, and service. ### Response #### Success Response (200) - **ref** (string) - Order reference number - **date** (string) - Order date - **labels** (array) - List of shipping label URLs ``` -------------------------------- ### Retrieve carrier services and details with PHP Source: https://context7.com/boxtal/php-library/llms.txt Use the CarriersList class to access carrier metadata, delivery zones, and service capabilities. The class provides detailed information on parcel points and content restrictions. ```php getCarriersList(); if (!$lib->curl_error && !$lib->resp_error) { echo "=== Available Carriers and Services ===\n"; foreach ($lib->carriers as $carrier) { echo "\n{$carrier['ope_name']} ({$carrier['ope_code']})\n"; echo " Service: {$carrier['srv_name_fo']} ({$carrier['srv_code']})\n"; echo " Description: {$carrier['description']}\n"; echo " Family: {$carrier['family']}\n"; echo " Delivery Type: {$carrier['delivery_type']}\n"; echo " Delivery Time: {$carrier['delivery_due_time']}\n"; // Zone coverage echo " Zones: "; if ($carrier['zone_fr']) echo "France "; if ($carrier['zone_es']) echo "Spain "; if ($carrier['zone_eu']) echo "EU "; if ($carrier['zone_int']) echo "International "; echo "\n"; // Parcel point information echo " Pickup Point: " . ($carrier['parcel_pickup_point'] ? 'Yes' : 'No') . "\n"; echo " Dropoff Point: " . ($carrier['parcel_dropoff_point'] ? 'Yes' : 'No') . "\n"; // Allowed content types if (!empty($carrier['allowed_content'])) { echo " Allowed Contents:\n"; foreach (array_slice($carrier['allowed_content'], 0, 3) as $content) { echo " - {$content['label']}\n"; } } // Service details if (!empty($carrier['details'])) { echo " Details:\n"; foreach ($carrier['details'] as $detail) { echo " - {$detail}\n"; } } } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } /* Sample structure: Array( 'ope_code' => 'CHRP', 'ope_name' => 'Chronopost', 'srv_code' => 'Chrono13', 'srv_name_fo' => 'Chronopost 13h', 'description' => 'Delivery before 1pm next day', 'family' => 'express', 'zone_fr' => '1', 'zone_eu' => '1', 'parcel_pickup_point' => '0', 'parcel_dropoff_point' => '1', 'allowed_content' => array(...) ) */ ``` -------------------------------- ### List Pickup and Dropoff Points for Multiple Carriers Source: https://context7.com/boxtal/php-library/llms.txt Use the ListPoints class to search for parcel points near a specified location across multiple carriers. Ensure the vendor autoloader is included and define the carriers and destination details. ```php 'dest', // 'exp' for pickup (shipper), 'dest' for delivery (recipient) 'pays' => 'FR', 'cp' => '75011', 'ville' => 'Paris' ); $lib = new ListPoints(); $lib->getListPoints($carriers, $destination); if (!$lib->curl_error && !$lib->resp_error) { foreach ($lib->list_points as $carrierPoints) { echo "\n=== {$carrierPoints['operator']} - {$carrierPoints['service']} ===\n"; if (empty($carrierPoints['points'])) { echo "No points available\n"; continue; } foreach ($carrierPoints['points'] as $point) { echo "\n[{$point['code']}] {$point['name']}\n"; echo " Address: {$point['address']}, {$point['zipcode']} {$point['city']}\n"; echo " Coordinates: {$point['latitude']}, {$point['longitude']}\n"; echo " Phone: {$point['phone']}\n"; echo " Description: {$point['description']}\n"; // Display opening hours echo " Schedule:\n"; foreach ($point['schedule'] as $day) { $morning = ($day['open_am'] && $day['close_am']) ? "{$day['open_am']}-{$day['close_am']}" : "Closed"; $afternoon = ($day['open_pm'] && $day['close_pm']) ? "{$day['open_pm']}-{$day['close_pm']}" : "Closed"; echo " {$day['weekday']}: AM: {$morning}, PM: {$afternoon}\n"; } } } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } ``` -------------------------------- ### Perform Multiple Quotation Requests in Parallel Source: https://context7.com/boxtal/php-library/llms.txt Use `getQuotationMulti` to send multiple shipment quotation requests concurrently. This method is ideal for comparing rates across different shipments simultaneously, optimizing performance. Ensure the `Emc\ ```php array( 'country' => 'FR', 'zipcode' => '75002', 'city' => 'Paris', 'address' => '15 rue Marsollier', 'type' => 'company' ), 'to' => array( 'country' => 'FR', 'zipcode' => '33000', 'city' => 'Bordeaux', 'address' => '24, rue des Ayres', 'type' => 'individual' ), 'parcels' => array( 'type' => 'colis', 'dimensions' => array( 1 => array('poids' => 1, 'longueur' => 15, 'largeur' => 16, 'hauteur' => 8) ) ), 'additional_params' => array( 'collection_date' => date('Y-m-d'), 'delay' => 'aucun', 'content_code' => 10120 ) ), // Second shipment array( 'from' => array( 'country' => 'FR', 'zipcode' => '75002', 'city' => 'Paris', 'address' => '15 rue Marsollier', 'type' => 'company' ), 'to' => array( 'country' => 'DE', 'zipcode' => '10115', 'city' => 'Berlin', 'address' => 'Unter den Linden 1', 'type' => 'individual' ), 'parcels' => array( 'type' => 'colis', 'dimensions' => array( 1 => array('poids' => 2, 'longueur' => 20, 'largeur' => 15, 'hauteur' => 10) ) ), 'additional_params' => array( 'collection_date' => date('Y-m-d'), 'delay' => 'aucun', 'content_code' => 10120, 'colis.valeur' => '100.00' ) ) ); $lib = new Quotation(); $lib->getQuotationMulti($multiRequest); // Results are indexed by request order foreach ($lib->offers as $index => $shipmentOffers) { echo "=== Shipment " . ($index + 1) . " ===\n"; if ($shipmentOffers === false) { echo "Error fetching quotes for this shipment\n"; continue; } foreach ($shipmentOffers as $offer) { echo $offer['operator']['label'] . " - " . $offer['price']['tax-inclusive'] . " EUR\n"; } } ``` -------------------------------- ### Retrieve Content Categories and Types Source: https://context7.com/boxtal/php-library/llms.txt The `ContentCategory` class fetches available content categories and types, which are necessary for quotation and order requests. It also allows loading all categories and contents, and retrieving specific contents by category code. Errors during the API call are handled and reported. ```php getCategories(); // Load all content types $lib->getContents(); if (!$lib->curl_error && !$lib->resp_error) { // Display categories echo "=== Content Categories ===\n"; foreach ($lib->categories as $code => $category) { echo "[{$code}] {$category['label']}\n"; } // Display contents grouped by category echo "\n=== Content Types ===\n"; foreach ($lib->contents as $categoryCode => $contentList) { echo "\nCategory: {$lib->categories[$categoryCode]['label']}\n"; foreach ($contentList as $content) { $prohibited = $content['prohibited'] ? ' [PROHIBITED]' : ''; echo " [{$content['code']}] {$content['label']}{$prohibited}\n"; } } // Get contents for a specific category $electronicsContents = $lib->getChild('10000'); // Electronics category foreach ($electronicsContents as $content) { echo $content['code'] . ": " . $content['label'] . "\n"; } } else { foreach ($lib->resp_errors_list as $error) { echo "Error: " . $error['message'] . "\n"; } } /* Sample output: === Content Categories === [10000] High-tech, electronics [20000] Home, garden, DIY [30000] Fashion, accessories [40000] Culture, leisure === Content Types === Category: High-tech, electronics [10120] Computer, tablet, smartphone [10130] Photo, video equipment [10140] TV, hifi, home cinema */ ``` -------------------------------- ### Quotation Class - getQuotationMulti Source: https://context7.com/boxtal/php-library/llms.txt The `getQuotationMulti` method allows for parallel quotation requests, optimizing performance when comparing rates for multiple shipments simultaneously. ```APIDOC ## Quotation Class - getQuotationMulti ### Description Performs multiple quotation requests in parallel using curl multi for improved performance when comparing rates for multiple shipments simultaneously. ### Method POST (implied by the nature of the request, though not explicitly stated as an HTTP method in the source) ### Endpoint Not explicitly defined in the source, but likely an internal method of the `Quotation` class. ### Parameters #### Request Body - **multiRequest** (array) - Required - An array where each element represents a shipment request with details such as 'from', 'to', 'parcels', and 'additional_params'. - **from** (array) - Required - Sender's address details. - **country** (string) - Required - Sender's country code. - **zipcode** (string) - Required - Sender's postal code. - **city** (string) - Required - Sender's city. - **address** (string) - Required - Sender's street address. - **type** (string) - Required - Sender's address type (e.g., 'company', 'individual'). - **to** (array) - Required - Recipient's address details. - **country** (string) - Required - Recipient's country code. - **zipcode** (string) - Required - Recipient's postal code. - **city** (string) - Required - Recipient's city. - **address** (string) - Required - Recipient's street address. - **type** (string) - Required - Recipient's address type (e.g., 'company', 'individual'). - **parcels** (array) - Required - Details about the parcels. - **type** (string) - Required - Type of parcel (e.g., 'colis'). - **dimensions** (array) - Required - Array of parcel dimensions. - **poids** (float) - Required - Weight of the parcel. - **longueur** (integer) - Required - Length of the parcel. - **largeur** (integer) - Required - Width of the parcel. - **hauteur** (integer) - Required - Height of the parcel. - **additional_params** (array) - Optional - Additional parameters for the quotation. - **collection_date** (string) - Optional - The desired collection date. - **delay** (string) - Optional - Shipping delay preference. - **content_code** (integer) - Optional - Code representing the content type. - **colis.valeur** (string) - Optional - Declared value of the parcel. ### Request Example ```php { "from": { "country": "FR", "zipcode": "75002", "city": "Paris", "address": "15 rue Marsollier", "type": "company" }, "to": { "country": "FR", "zipcode": "33000", "city": "Bordeaux", "address": "24, rue des Ayres", "type": "individual" }, "parcels": { "type": "colis", "dimensions": [ { "poids": 1, "longueur": 15, "largeur": 16, "hauteur": 8 } ] }, "additional_params": { "collection_date": "2023-10-27", "delay": "aucun", "content_code": 10120 } } ``` ### Response #### Success Response (200) - **offers** (array) - An array containing quotation offers for each shipment request, indexed by the order of the request. - Each element in the offers array is either `false` (if an error occurred for that shipment) or an array of offers. - Each offer contains: - **operator** (object) - Information about the shipping operator. - **label** (string) - The name of the operator. - **price** (object) - Pricing details. - **tax-inclusive** (string) - The price including tax. #### Response Example ```json { "offers": [ [ { "operator": {"label": "La Poste"}, "price": {"tax-inclusive": "10.50 EUR"} }, { "operator": {"label": "Chronopost"}, "price": {"tax-inclusive": "12.00 EUR"} } ], [ { "operator": {"label": "DHL"}, "price": {"tax-inclusive": "25.00 EUR"} } ] ] } ``` ``` -------------------------------- ### Handle API Errors with Quotation Class Source: https://context7.com/boxtal/php-library/llms.txt Provides a generic function to handle both cURL connection errors and API response errors. It checks for `curl_error` and `resp_error` properties and logs relevant error details. ```php curl_error) { // Network/connection errors echo "Connection Error: " . $lib->curl_error_text . "\n"; echo "Error Number: " . $lib->curl_errno . "\n"; return; } if ($lib->resp_error) { // API response errors foreach ($lib->resp_errors_list as $error) { echo "API Error [{$error['code']}]: {$error['message']}\n"; if (isset($error['url'])) { echo " URL: {$error['url']}\n"; } } return; } } $lib = new Quotation(); $lib->getQuotation($from, $to, $parcels, $additionalParams); if ($lib->curl_error || $lib->resp_error) { handleApiErrors($lib); } else { // Process successful response echo "Found " . count($lib->offers) . " shipping offers\n"; } // Access raw API response for debugging echo "Last API Request:\n"; print_r($lib->getApiParam()); echo "Raw Response:\n"; echo $lib->last_request; ``` -------------------------------- ### ContentCategory Class Source: https://context7.com/boxtal/php-library/llms.txt The `ContentCategory` class is used to retrieve available content categories and content types, which are essential for quotation and order requests. Content codes specify the nature of the items being shipped. ```APIDOC ## ContentCategory Class ### Description Retrieves available content categories and content types required for quotation and order requests. Content codes describe the nature of items being shipped. ### Method GET (implied by the nature of the request, though not explicitly stated as an HTTP method in the source) ### Endpoint Not explicitly defined in the source, but likely internal methods of the `ContentCategory` class. ### Methods - **getCategories()**: Loads all available content categories. - **getContents()**: Loads all available content types. - **getChild(string $categoryCode)**: Retrieves content types for a specific category. ### Response #### Success Response (200) - **categories** (array) - An associative array of content categories, keyed by category code. - Each category contains: - **label** (string) - The display name of the category. - **contents** (array) - An associative array of content types, keyed by category code. - Each category's value is an array of content types, where each content type contains: - **code** (integer) - The code for the content type. - **label** (string) - The display name of the content type. - **prohibited** (boolean) - Indicates if the content type is prohibited. #### Response Example ```json { "categories": { "10000": {"label": "High-tech, electronics"}, "20000": {"label": "Home, garden, DIY"} }, "contents": { "10000": [ {"code": 10120, "label": "Computer, tablet, smartphone", "prohibited": false}, {"code": 10130, "label": "Photo, video equipment", "prohibited": false} ], "20000": [ {"code": 20100, "label": "Furniture", "prohibited": false} ] } } ``` ### Error Handling - **curl_error** (boolean) - True if a cURL error occurred. - **resp_error** (boolean) - True if a response error occurred. - **resp_errors_list** (array) - A list of response errors, each containing a 'message' field. ```