PHP code example of mvenghaus / saloon-magento2-connector

1. Go to this page and download the library: Download mvenghaus/saloon-magento2-connector 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/ */

    

mvenghaus / saloon-magento2-connector example snippets



$configuration = new Configuration(...);
$connector = new ApiConnector($configuration);

$response = $connector->send(new Your_Request());

class Configuration
{
    public function __construct(
        public string $endpoint, // https://www.your-domain.com/rest/V1/
        public string $username,
        public string $password,
        public int $tokenLifetime = 0, // admin defined token lifetime in seconds 
        public ?string $authenticator = null, // saloon authenticator (serialized)
        public ?Closure $authenticatorUpdateCallback = null, // callback to save authenticator if changed
        public ?Closure $debugCallback = null // callback for debugging
    ) {
    }
}

$authenticator = load_from_your_cache();

$configuration = new Configuration(
    'https://www.your-domain.com/rest/V1/',
    'USERNAME',
    'PASSWORD',
    3600,
    $authenticator,
    function (string $authenticator) {
        save_to_your_cache($authenticator);
    },
    function (PendingRequest $pendingRequest, RequestInterface $psrRequest) {
        echo $pendingRequest->getUrl() . PHP_EOL;
    }
);