PHP code example of webkult / shirtigo-php-api-wrapper

1. Go to this page and download the library: Download webkult/shirtigo-php-api-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webkult / shirtigo-php-api-wrapper example snippets




use Webkult\Api\Shirtigo\WebkultApiShirtigo;

// Initialize the API client
$api = new WebkultApiShirtigo();

// Set your API key
$api->withTokenAuth('your-api-key-here');

// Access different API resources
$catalogApi = $api->catalogApi();
$orderApi = $api->orderApi();
$designApi = $api->designApi();



use Webkult\Api\Shirtigo\WebkultApiShirtigo;

$api = new WebkultApiShirtigo();

// OAuth2 flow
$oauth = $api->oauth();
$accessToken = $oauth->requestAccessToken([
    'client_id' => 'your-client-id',
    'client_secret' => 'your-client-secret',
    'grant_type' => 'client_credentials'
]);

// Use the access token
$api->withTokenAuth($accessToken);



$catalogApi = $api->catalogApi();

// Get all base products
$products = $catalogApi->getAllBaseProducts();

// Get a specific product
$product = $catalogApi->getBaseProduct('product-id');

// List available categories
$categories = $catalogApi->listAvailableCategories();



$orderApi = $api->orderApi();

// Create a new order
$order = $orderApi->createOrder([
    'products' => [
        [
            'product_id' => 'base-product-id',
            'quantity' => 1,
            'customizations' => [
                // Customization options
            ]
        ]
    ],
    'shipping_address' => [
        // Address details
    ]
]);

// Get order details
$orderDetails = $orderApi->getOrder($order['id']);

// Calculate order price
$price = $orderApi->calculatePrice([
    'products' => $order['products']
]);



$designApi = $api->designApi();

// Create design from file
$design = $designApi->createDesignFromFile([
    'file' => '/path/to/design.png',
    'name' => 'My Design'
]);

// Create design from URL
$design = $designApi->createDesignFromUrl([
    'url' => 'https://example.com/design.png',
    'name' => 'Design from URL'
]);

// Get all designs
$designs = $designApi->getAllDesigns();

// Update design
$designApi->updateDesign($design['id'], [
    'name' => 'Updated Design Name'
]);



$imageApi = $api->imageApi();

// Generate mockup images
$mockups = $imageApi->generateMockupImages([
    'design_id' => 'design-id',
    'product_id' => 'product-id',
    'variations' => ['front', 'back']
]);

// Remove background from image
$processedImage = $imageApi->removeBackground([
    'image_url' => 'https://example.com/image.png'
]);

// Upscale design
$upscaledDesign = $imageApi->upscaleDesign([
    'design_id' => 'design-id',
    'scale_factor' => 2
]);



try {
    $products = $catalogApi->getAllBaseProducts();
} catch (\Saloon\Exceptions\RequestException $e) {
    // Handle HTTP errors
    echo "Request failed: " . $e->getMessage();
} catch (\Exception $e) {
    // Handle other errors
    echo "Error: " . $e->getMessage();
}