user8457287 user8457287 - 1 year ago 88
PHP Question

Array does not work in GetCompetitivePricingForASINSample Amazon MWS PHP

I want to request from a text file with the ASINS (1 AINS in 1 Line). But I always get an error. The file has no more than 20 ASINs.
I get error


"Warning: rawurlencode() expects parameter 1 to be string, array given
in C:\xampp\htdocs\MarketplaceWebServiceProducts\Client.php on line
1405
or

Caught Exception: parameter ASINList.ASIN.1 failed a validation check:
Extraneous whitespace for input value: " " Response Status Code: 400
Error Code: InvalidRequest Error Type


$arr = file("asin.txt");
$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
$request->setSellerId(MERCHANT_ID);
$request->setMarketplaceId(MARKETPLACE_ID);
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asin_list->setASIN(array($arr));

$request->setASINList($asin_list);


If I write so, does not work.

$asin_list->setASIN(array($arr[0],$arr[1]));


If I write so, then works

$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();
$asin_list->setASIN(array('0470165057' ,'3944660110'
,'3000383964' ,'3000567852'....


How do I make a request from a file with a list (1 request 20 ASINs) from the file with 1000 ASINS?

Please help me.
And apologies for my english

PS.
Result from Asin.txt with print_r


Array ( [0] => 3944660110 [1] => 3000383964 [2] => 3000400567 [3] =>
3000449523 [4] => 3000489169 [5] => 3000518290 [6] => 3000539069 )


asin.txt - 1 Line 1 ASIN

$request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
$request->setSellerId(MERCHANT_ID);

$arr = file('asin.txt',FILE_IGNORE_NEW_LINES);
$arr_chunks = array_chunk($arr, 20, TRUE);

$request->setMarketplaceId(MARKETPLACE_ID);
$asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();

//$asin_list->setASIN($arr_chunks[0]);
//$request->setASINList($asin_list);

If $ asin_list-> setASIN ($ arr_chunks [0]); - Works
If $ asin_list-> setASIN ($ arr_chunks [1]); - Dont Work

Answer Source

You could use array_chunk() to divide your 1000 asins into group of 20s e.g.

$asins_chunks = array_chunk($asins_array, 20, TRUE);

I use this code and it works:

$service = new
 MarketplaceWebServiceProducts_Client($this->aws_access_key,
 $this->aws_secret_access_key, $this->application_name,
 $this->application_version, $this->config);

 $request = new MarketplaceWebServiceProducts_Model_GetLowestOfferListingsForASINRequest();
 $request->setSellerId($this->seller_id);
 $request->setMarketplaceId($this->marketplace_id);

 //requesting product's data for "New" products
 $request->setItemCondition("New");

 //excluding our price data in product api response
 $request->setExcludeMe(TRUE);

 $asin_list = new MarketplaceWebServiceProducts_Model_ASINListType();

 //creating $iec_asins array for returning price data back
 $asins = array("ASIN1","ASIN2","ASIN3");

 $asin_list->setASIN($asins);
 $request->setASINList($asin_list);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download