jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
404 stars 198 forks source link

[getOrders] not passing data_elements to amazon SP API #547

Closed MichalOrm closed 1 year ago

MichalOrm commented 1 year ago

Problem description:

ON every marketplace: Request getOrders always returning empty buyerInfo and shippingAddress no matter what i pass in restricted data parameter (filled with array ['buyerInfo', 'shippingAddress'], not filled at all, filled with deliberate bug)

On every marketplace (except US) No error when requesting single order /getOrder/{orderID} and also full buyer information are returned

On US AFN market I can generate error when requesting single order /getOrder/{orderID} and passing restrictedElements Application does not have access to one or more requested data elements: [buyerInfo, shippingAddress] (meand client havbe no access to those), but when calling

From my perspective and those examples on US marketplace it looks like getOrders is not correctly passing [data_elements] parameter or AMZ api is ignoring it.

Error:

No error, just empty fields in response, or error for US marketplace (but this is expected, as client hasnt been authorized): Application does not have access to one or more requested data elements: [buyerInfo, shippingAddress] (meand client havbe no access to those), but when calling

# Your error here. PLEASE make sure to redact secrets from your error log!

Code

$client = new OrdersV0Api($this->config);
$request = new GetOrdersRequest();
$request->setMarketplaceIds([$data['MarketplaceId']]);
$request->setCreatedAfter((new DateTime())->modify('-14 day')->format(Enums::DATETIME_ISO18601));
$request->setDateElements(['buyerInfo', 'shippingAddress']);
$response = $client->doRequest('getOrders', $request);
MichalOrm commented 1 year ago

Also from logs i can see that guzzleHttp doesent have restricted_data element:

GuzzleHttp\Psr7\Request Object
(
    [method:GuzzleHttp\Psr7\Request:private] => GET
    [requestTarget:GuzzleHttp\Psr7\Request:private] => 
    [uri:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Uri Object
        (
            [scheme:GuzzleHttp\Psr7\Uri:private] => https
            [userInfo:GuzzleHttp\Psr7\Uri:private] => 
            [host:GuzzleHttp\Psr7\Uri:private] => sellingpartnerapi-eu.amazon.com
            [port:GuzzleHttp\Psr7\Uri:private] => 
            [path:GuzzleHttp\Psr7\Uri:private] => /orders/v0/orders
            [query:GuzzleHttp\Psr7\Uri:private] => CreatedAfter=2023-05-21T13%3A10%3A38Z&OrderStatuses=Unshipped&MarketplaceIds=AMEN7PMS3EDWL&MaxResultsPerPage=100
            [fragment:GuzzleHttp\Psr7\Uri:private] => 
        )

    [headers:GuzzleHttp\Psr7\Request:private] => Array
        (
            [User-Agent] => Array
                (
                    [0] => jlevers/selling-partner-api/5.1.0 (Language=PHP)
                )

            [Accept] => Array
                (
                    [0] => application/json
                )

            [Content-Type] => Array
                (
                    [0] => application/json
                )

            [Host] => Array
                (
                    [0] => sellingpartnerapi-eu.amazon.com
                )

            [Authorization] => Array
                (
                    [0] =>...
                )

            [x-amz-date] => Array
                (
                    [0] => 20230522T111039Z
                )

            [x-amz-access-token] => Array
                (
                    [0] => ...
                )

        )

    [headerNames:GuzzleHttp\Psr7\Request:private] => Array
        (
            [user-agent] => User-Agent
            [accept] => Accept
            [content-type] => Content-Type
            [host] => Host
            [authorization] => Authorization
            [x-amz-date] => x-amz-date
            [x-amz-access-token] => x-amz-access-token
        )

    [protocol:GuzzleHttp\Psr7\Request:private] => 1.1
    [stream:GuzzleHttp\Psr7\Request:private] => GuzzleHttp\Psr7\Stream Object
        (
            [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #705
            [size:GuzzleHttp\Psr7\Stream:private] => 
            [seekable:GuzzleHttp\Psr7\Stream:private] => 1
            [readable:GuzzleHttp\Psr7\Stream:private] => 1
            [writable:GuzzleHttp\Psr7\Stream:private] => 1
            [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
            [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                (
                )

        )

)
jlevers commented 1 year ago

In your code you're calling setDateElements, not setDataElements, which I'm guessing is the source of the issue. It also looks like you've either made some modifications to the library or are using another library altogether, because there is no GetOrdersRequest class in this library, and the $client->doRequest() call also does not exist in this library. Not knowing exactly what code you're using makes it hard for me to figure out what other possible sources of the problem might be.

You won't see the dataElements in the request, because those values are used to make a separate request ahead of time to retrieve a restricted data token, which is needed to get PII.

jlevers commented 1 year ago

Closing due to inactivity.