0

I try to make a GetItemTransactions call to the eBay API. The call basically works fine, but returns only the last transaction (itemID).

I think there is an error in my cURL syntax because I use the same URL ($url) and I would appreciate some help. Here is the code:

$mh = curl_multi_init();
$handles = array();

$i = 0;

$urls = array("https://api.ebay.com/ws/api.dll",
              "https://api.ebay.com/ws/api.dll",
              "https://api.ebay.com/ws/api.dll");

foreach ($urls as $url)
{
$handles[$url] = curl_init($url);

curl_setopt($handles[$url], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handles[$url], CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($handles[$url], CURLOPT_HTTPHEADER, $headers);
curl_setopt($handles[$url], CURLOPT_POST, 1);
curl_setopt($handles[$url], CURLOPT_POSTFIELDS, $xml_request[$i]);
curl_setopt($handles[$url], CURLOPT_RETURNTRANSFER, true);

curl_multi_add_handle($mh, $handles[$url]);

$i++;

}

The $headers (they are the same anyway) and $xml_request variables are transmitted correctly. I presume the $handles[$url] gets overwritten because it's the same in each loop?

yello
  • 191
  • 1
  • 13

1 Answers1

0

I found the answer from a similar question/answer here:

Can I execute a multiple parallel cURL against the same URL?

Here the new working code:

$mh = curl_multi_init();
$handles = array();

$i = 0;

$url = "https://api.ebay.com/ws/api.dll";

$stationIds = array(207,303,305);

foreach ($stationIds as $stationId)
{

$handles[$stationId] = curl_init();
curl_setopt($handles[$stationId], CURLOPT_URL, $url);

curl_setopt($handles[$stationId], CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($handles[$stationId], CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($handles[$stationId], CURLOPT_HTTPHEADER, $headers);
curl_setopt($handles[$stationId], CURLOPT_POST, 1);
curl_setopt($handles[$stationId], CURLOPT_POSTFIELDS, $xml_request[$i]);
curl_setopt($handles[$stationId], CURLOPT_RETURNTRANSFER, true);
curl_setopt($handles[$stationId], CURLOPT_FORBID_REUSE,1); 
curl_setopt($handles[$stationId], CURLOPT_FRESH_CONNECT,1); 

curl_multi_add_handle($mh, $handles[$stationId]);

$i++;

}

Note: you need to adjust the number of $stationIds to the number of items you send. eBay allows a maximum of 18 parallel API calls.

Community
  • 1
  • 1
yello
  • 191
  • 1
  • 13