selling-partner-api
selling-partner-api copied to clipboard
[Product Pricing API] string serialize error in v5.4.0
Problem description:
Thank you for releasing v5.4.0.
I got an exception that wasn't there in v5.3.0.
Error:
Uncaught exception InvalidArgumentException: 0 - Invalid value for enum '\SellingPartnerApi\Model\ProductPricingV0\FulfillmentChannelType', must be one of: 'Amazon', 'Merchant' in vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php on line 85
Code
$api = new ProductPricingV0Api($config);
$response = $api->getItemOffers($marketplace_ids, $item_condition, $asin);
$summary = $response->getPayload()->getSummary();
echo (string)$summary;
I have also encountered this bug/error but in my case it was in relation to the ConditionType. I believe this error to have been caused by commit bd890b90ff047ec5fd85052f04a698aa41103df7 which seems to have been authored as a remedy to #399
Line 82 converts the $value to uppercase but this is a breaking change if the enum values (strings) are not also converted to upper case.
I would happily submit a pull request to fix the issue but it all depends on the correct approach, the options are as follows....
- Revert the commit and fix #399 in a different way.
- Do some thing similar to .... $allowedEnumTypes = array_map('strtoupper', $allowedEnumTypes); to convert the $allowedEnumTypes array to uppercase also.
It all depends on if the $allowedEnumTypes values are to be case sensitive and how this is documented in the sp-api.
The ENUM values are auto-generated from the swagger model I think. Also, issue #399 is because Amazon returns values inconsistent with their own swagger model 😤
@gokigoks This somehow does not surprise me.... unfortunately I feel it only makes a solution harder to commit to.
I have also encountered this bug/error but in my case it was in relation to the ConditionType. I believe this error to have been caused by commit bd890b9 which seems to have been authored as a remedy to #399
Line 82 converts the $value to uppercase but this is a breaking change if the enum values (strings) are not also converted to upper case.
I would happily submit a pull request to fix the issue but it all depends on the correct approach, the options are as follows....
1. Revert the commit and fix [Image Variant Error #399](https://github.com/jlevers/selling-partner-api/issues/399) in a different way. 2. Do some thing similar to .... $allowedEnumTypes = array_map('strtoupper', $allowedEnumTypes); to convert the $allowedEnumTypes array to uppercase also.
It all depends on if the $allowedEnumTypes values are to be case sensitive and how this is documented in the sp-api.
Can confirm that the ConditionType currently breaks because of the strtoupper().
$enumVal = "USED";
$allowedEnumTypes = array:5 [▼
0 => "New"
1 => "Used"
2 => "Collectible"
3 => "Refurbished"
4 => "Club"
];
Which breaks in the line 83
in_array($enumVal, $allowedEnumTypes, true)
The question as to the correct approach still remains though... Should allowed enum types be case sensitive? From what I understand from other comments the Amazon api does not respond with them in a consistent form. Does anyone know if they accept them in say, all lower case or do they expect them to be submitted in the form in their docs?
The fix is simple... the correct approach seems to be more complicated.
Maybe it could be fixed by forcing a case-insensitive comparison?
if (in_array(strtolower($enumVal), array_map("strtolower", $allowedEnumTypes), true))
This should be fixed in v5.4.1
-- give it a try and let me know if you're still having issues.
Thank you for releasing v5.4.1.
This issue has been resolved.