Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getOrderItems() response throws exception #799

Closed
pokusman opened this issue Oct 29, 2024 · 14 comments
Closed

getOrderItems() response throws exception #799

pokusman opened this issue Oct 29, 2024 · 14 comments

Comments

@pokusman
Copy link

Amazon made a small unannounced change in SP API yesterday and the 'getOrderItems' function. The called function returns incomplete data, namely 'ResponsibleParty' which is sometimes empty and end up as throws exception. In this case I recommend to just disable validation in '/vendor/jlevers/selling-partner-api/lib/Model/OrdersV0/TaxCollection.php

Fatal error: Uncaught InvalidArgumentException: Invalid value '' for 'responsible_party', must be one of 'AMAZON SERVICES, INC.', 'AMAZON COMMERCIAL SERVICES PTY LTD' in ..../vendor/jlevers/selling-partner-api/lib/Model/OrdersV0/TaxCollection.php:265 Stack trace: #0 ..../vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php(385): SellingPartnerApi\Model\OrdersV0\TaxCollection->setResponsibleParty('') #1 ..../vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php(385): SellingPartnerApi\ObjectSerializer::deserialize(Object(stdClass), '\SellingPartner...', NULL) #2 ..../vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php(276): SellingPartnerApi\ObjectSerializer::deserialize(Object(stdClass), '\SellingPartner...', NULL) #3 ..../vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php(385): SellingPartnerApi\ObjectSerializer::deserialize(Array, '\SellingPartner...', NULL) #4 ..../vendor/jlevers/selling-partner-api/lib/ObjectSerializer.php(385): SellingPartnerApi\ObjectSerializer::deserialize(Object(stdClass), '\SellingPartner...', NULL) #5 ..../vendor/jlevers/selling-partner-api/lib/Api/OrdersV0Api.php(1543): SellingPartnerApi\ObjectSerializer::deserialize(Object(stdClass), '\SellingPartner...', Array) #6 ..../vendor/jlevers/selling-partner-api/lib/Api/OrdersV0Api.php(1472): SellingPartnerApi\Api\OrdersV0Api->getOrderItemsWithHttpInfo('171-7392580-949...', '', Array) #7 ..../servers/Amazons/GetOrders.php(438): SellingPartnerApi\Api\OrdersV0Api->getOrderItems('171-7392580-949...', '', Array) #8 {main} thrown in ..../vendor/jlevers/selling-partner-api/lib/Model/OrdersV0/TaxCollection.php on line 265

Solution:

Screenshot 2024-10-29 090350
@dv336699
Copy link

Using version 5.10.1 - getting the same response since yesterday.

@adamtoms
Copy link
Contributor

adamtoms commented Oct 29, 2024

same issue here even after upgrading to 5.10.2. Have also tried: 5.8.3 and same issue.

@adamtoms
Copy link
Contributor

adamtoms commented Oct 29, 2024

@dv336699 & @pokusman if you need a quick resolution, in TaxCollection.php:264 add

if($responsible_party == ""){
    return $allowedValues[0];
}

Looking into the root cause now.

@pokusman
Copy link
Author

@adamtoms A more elegant solution ;-)

@adamtoms
Copy link
Contributor

adamtoms commented Oct 29, 2024

so I can see the payload contains an empty string. Going to look at the amazon docs to see whats required.

{#2133 ▼ // vendor/jlevers/selling-partner-api/lib/Api/OrdersV0Api.php:1543
  +"payload": {#2124 ▼
    +"OrderItems": array:1 [▼
      0 => {#2129 ▼
        +"TaxCollection": {#2142 ▼
          +"Model": "MarketplaceFacilitator"
          +"ResponsibleParty": ""
        }

UPDATE: Looks like it's optional: https://developer-docs.amazon.com/sp-api/docs/orders-api-v0-reference#taxcollection

So just need the enforecement check removed from setResponsibleParty.

@tazplan
Copy link

tazplan commented Oct 29, 2024

As quick fix, based on adamtoms' solution, I simply modify TaxCollection.php (selling-partner-api\lib\Model\Orders\TaxCollection.php) by adding false&& in the condition of the public function setResponsibleParty like this:
if (false&&!is_null($responsible_party) &&!in_array(strtoupper($responsible_party), $allowedValues, true)) {
Now it works again :)

@dmellstrom
Copy link

@dv336699 & @pokusman if you need a quick resolution, in TaxCollection.php:264 add

if($responsible_party == ""){
    return $allowedValues[0];
}

Looking into the root cause now.

Thanks @adamtoms for the quick fix! Worked for me

@bxnxg
Copy link

bxnxg commented Oct 30, 2024

Manu thanks for your issue, I investigate also yesterday and find your solutions.
That unbelievable that Amazon's technical service won't inform us for change in theirs only one OrderV0 !

@pokusman
Copy link
Author

Any solution to a problem is better than none, especially when you really need it badly. There are more elegant solutions than mine, but the important thing was that it worked and helped to find better solutions by people who have more experience with coding than me. We all know how Amazon Support works :-D

@tkasa
Copy link

tkasa commented Oct 30, 2024

My understanding is that this is an optional field so I went with skipping validation if the value is an empty string for now.

edit: raised a draft PR for it here: #802

if (
    // Amazon may send this optional field as an empty string so we have to cater for that scenario here
    // @see https://github.com/jlevers/selling-partner-api/issues/799
    $responsible_party !== ''
    && !is_null($responsible_party)
    && !in_array(strtoupper($responsible_party), $allowedValues, true)
) {
    throw new \InvalidArgumentException(
        sprintf(
            "Invalid value '%s' for 'responsible_party', must be one of '%s'",
            $responsible_party,
            implode("', '", $allowedValues)
        )
    );
}

@nhupham-commonservices
Copy link

My understanding is that this is an optional field so I went with skipping validation if the value is an empty string for now.

edit: raised a draft PR for it here: #802

if (
    // Amazon may send this optional field as an empty string so we have to cater for that scenario here
    // @see https://github.com/jlevers/selling-partner-api/issues/799
    $responsible_party !== ''
    && !is_null($responsible_party)
    && !in_array(strtoupper($responsible_party), $allowedValues, true)
) {
    throw new \InvalidArgumentException(
        sprintf(
            "Invalid value '%s' for 'responsible_party', must be one of '%s'",
            $responsible_party,
            implode("', '", $allowedValues)
        )
    );
}

Thanks @tkasa! It works for me

@salyangoz
Copy link

Same issue waiting for a new release in order to include our system.

@PRodO5lNk5
Copy link

@pokusman Can we consider this fixed? It seems #805 also addresses this

@pokusman
Copy link
Author

pokusman commented Nov 7, 2024

yes :) we can. Thanks for help and professional response.

@jlevers jlevers closed this as completed Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests