PHP code example of mcrock / allegroapi

1. Go to this page and download the library: Download mcrock/allegroapi 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/ */

    

mcrock / allegroapi example snippets


composer 

$credentials = new Credentials([
    'restClientId' => 'yourClientId',
    'restClientSecret' => 'yourClientSecret',
    'restApiKey' => 'yourApiKey',
    'restRedirectUri' => 'yourRedirectUri',
    'soapApiKey' => 'yourSoapApiKey',
]);

$client = new RestClient($credentials);
$authService = $client->getAuthService();

//now redirect to URL generated from this method:
header('Location: '.$authService->getAuthUrl());

$code = $_GET['code'];

$token = $authService->getNewToken($code);

$newToken = $authService->refreshToken($token);

$request = new Request('GET', 'pricing/offer-quotes', null, ['offer.id' => '123123123']);
$response = $client->sendRequest($token, $request);

var_dump(json_decode((string) $response->getBody()));

$request = new PutChangePriceCommandRequest('123123123', '123.45');
$response = $client->sendRequest($token, $request);

var_dump(json_decode((string) $response->getBody()));