PHP code example of exchangegroup / exchangegroup-api
1. Go to this page and download the library: Download exchangegroup/exchangegroup-api 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/ */
exchangegroup / exchangegroup-api example snippets
nt = new ExchangeGroup\Client('username', 'password');
// retrieving more information about one random advert from that list
$adverts = $client->getAdverts();
// updating the title and price of one random advert from that list
$randomAdvert = array_rand($adverts, 1);
$client->updateAdvert(
$advertToUpdate['id'],
array('title' => 'New Product Title', 'price' => '12.34')
);
// retrieving a list of variants from the server
$variants = $client->getVariants();
// retrieving more information about one variant advert from that list
$randomVariant = array_rand($variants, 1);
$variantDetails = $client->getVariant($randomVariant['id']);
// and from the list attached to the advert
foreach($randomAdvert['variant_ids'] as $variantId) {
var_dump($client->getVariant($variantId));
}
// OR
$advertVariants = array_map(
function($id) use ($client) { return $client->getVariant($id); },
$randomAdvert['variant_ids']
);
// updating the count_on_hand and sku of one of those variants
$client->updateVariant(
$advertVariants[0]['id'],
array('count_on_hand' => 1, 'sku' => 'A3334C')
);
try {
$client->updateVariant(
1234,
array('count_on_hand' => -3, 'sku' => 'A3334C')
);
} catch(ExchangeGroup\ClientException $e) {
// "Errors in API request - count_on_hand: must be greater than zero"
echo($e->getMessage());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.