Retrieve cross-sell campaigns
Overview
Use the searchCrossSellCampaigns method to extract information about the cross-sell campaigns you configured.
Parameters
Parameters |
Type |
Required |
Description |
---|---|---|---|
CampaignName |
String |
Optional |
The name of the campaign. |
Status |
String |
Optional |
The status of the campaign; can be ACTIVE/INACTIVE. |
Products |
Array of strings |
Optional |
Array of product codes to apply to this campaign. |
RecommendedProducts |
Array of strings |
Optional |
Array of product codes recommended to the shopper. |
StartDate |
String |
Optional |
The date when the cross-sell campaign starts, formatted as YYYY-MM-DD |
EndDate |
String |
Optional |
The date when the cross-sell campaign ends, formatted as YYYY-MM-DD |
Type | String | Optional | Can be MERCH/AFF. |
Pagination |
Object |
Optional |
|
Page |
Int |
Optional |
The page number of the results. |
Limit |
Int |
Optional |
The number of results per page. |
Response
Parameters | Type/Description |
---|---|
Items | An array of CrossSellCampaign Objects |
Pagination | Pagination Object with the following parameters: Page, Limit, Count |
Request
<?php
declare(strict_types=1);
// Start clear CLI
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
// End clear CLI
$executionStartTime = microtime(true);
$apiVersion = '6.0';
$apiHost = "http://api.avangate.local";
$host = $apiHost."/soap/" . $apiVersion . "/";
$client = new SoapClient(
$host."?wsdl",
[
'location' => $host,
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE
]
);
$client->__setCookie('XDEBUG_SESSION', 'PHPSTORM');
// Please be aware to consider valid data
$merchantCode = 'your_merchant_code';
$key = 'your_merchant_key';
// Generate hash for login
$date = gmdate('Y-m-d H:i:s');
$string = strlen($merchantCode) . $merchantCode . strlen($date) . $date;
$hash = hash_hmac('md5', $string, $key);
try {
$sessionID = $client->login($merchantCode, $date, $hash);
} catch (SoapFault $e) {
echo $e->getMessage();
}
var_dump("Generated sessionID: ". $sessionID);
echo "\n\r";
// Build search parameters
$searchOptions = new \stdClass();
$searchOptions->Status = ['ACTIVE']; // Optional | Ex: ['ACTIVE']
$searchOptions->Type = null; // Optional | Ex: 'MERCH'
$searchOptions->CampaignName = null; // Optional | Ex: 'UpdatedCampaign_4'
$searchOptions->Products = []; // Optional | Ex: ["a01", "a02"]
$searchOptions->RecommendedProducts = [];// Optional | Ex: ["a03"]
$searchOptions->StartDate = null; // Optional | Ex: 'YYYY-MM-DD'
$searchOptions->EndDate = null; // Optional | Ex: 'YYYY-MM-DD'
$searchOptions->Pagination = null; // Optional | Ex: {"Page": "1", "Limit": "10"}
try {
$result = $client->searchCrossSellCampaigns($sessionID, $searchOptions);
echo "\n\rSEARCH CROSS SELL CAMPAIGNS: \n\r";
print_r(json_encode($result, JSON_PRETTY_PRINT));
} catch (SoapFault $e) {
echo $e->getMessage();
}
$executionEndTime = microtime(true);
// The duration will be displayed in seconds and milliseconds.
$seconds = round($executionEndTime - $executionStartTime, 2);
// Print it out
echo "\n\rThis script took $seconds to execute.\n\r";