jlevers / selling-partner-api

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

Incomplete customer address at getOrder #388

Closed phploader closed 2 years ago

phploader commented 2 years ago

Hello, I am trying to retrieve order information with the following code: ` $config = new Configuration([ "lwaClientId" => "amzn1.application-oa2-client.xxx", "lwaClientSecret" => "7904axxxxx", "lwaRefreshToken" => "Atzr|xxxxxx", "awsAccessKeyId" => "AKIA4xxxxx", "awsSecretAccessKey" => "sLX3zoxxxxxxx", "endpoint" => Endpoint::EU ]);

    $apiInstance = new SellingPartnerApi\Api\OrdersV0Api($config);  
    $order_id = '302-8046517-XXXXXXX';  
    $data_elements = ['buyerInfo', 'shippingAddress'];

    try {
        $result = $apiInstance->getOrder($order_id, $data_elements);
        echo "<pre>"; print_r($result); echo "</pre>";
    } catch (Exception $e) {
        echo 'Exception when calling OrdersV0Api->getOrderAddress: ', $e->getMessage(), PHP_EOL;
    }`

In response I get the following result. As you can see, customer data is missing like name, first name, street:

`SellingPartnerApi\Model\OrdersV0\GetOrderResponse Object ( [container:protected] => Array ( [payload] => SellingPartnerApi\Model\OrdersV0\Order Object ( [container:protected] => Array ( [amazon_order_id] => 302-8046517-XXXXXXX [seller_order_id] => 302-8046517-XXXXXXX [purchase_date] => 2022-08-07T18:46:22Z [last_update_date] => 2022-08-08T01:16:16Z [order_status] => Shipped [fulfillment_channel] => AFN [sales_channel] => Amazon.de [order_channel] => [ship_service_level] => Expedited [order_total] => SellingPartnerApi\Model\OrdersV0\Money Object ( [container:protected] => Array ( [currency_code] => EUR [amount] => XX.XX )

                            )

                        [number_of_items_shipped] => 1
                        [number_of_items_unshipped] => 0
                        [payment_execution_detail] => 
                        [payment_method] => Other
                        [payment_method_details] => Array
                            (
                                [0] => Standard
                            )

                        [marketplace_id] => A1PA6795UKMFR9
                        [shipment_service_level_category] => Expedited
                        [easy_ship_shipment_status] => 
                        [cba_displayable_shipping_label] => 
                        [order_type] => StandardOrder
                        [earliest_ship_date] => 2022-08-08T21:59:59Z
                        [latest_ship_date] => 2022-08-08T21:59:59Z
                        [earliest_delivery_date] => 
                        [latest_delivery_date] => 
                        [is_business_order] => 
                        [is_prime] => 
                        [is_premium_order] => 
                        [is_global_express_enabled] => 
                        [replaced_order_id] => 
                        [is_replacement_order] => 
                        [promise_response_due_date] => 
                        [is_estimated_ship_date_set] => 
                        [is_sold_by_ab] => 
                        [is_iba] => 
                        [default_ship_from_location_address] => 
                        [buyer_invoice_preference] => 
                        [buyer_tax_information] => 
                        [fulfillment_instruction] => 
                        [is_ispu] => 
                        [is_access_point_order] => 
                        [marketplace_tax_info] => 
                        [seller_display_name] => 
                        [shipping_address] => SellingPartnerApi\Model\OrdersV0\Address Object
                            (
                                [container:protected] => Array
                                    (
                                        [name] => 
                                        [address_line1] => 
                                        [address_line2] => 
                                        [address_line3] => 
                                        [city] => Berlin
                                        [county] => 
                                        [district] => 
                                        [state_or_region] => 
                                        [municipality] => 
                                        [postal_code] => 12059
                                        [country_code] => DE
                                        [phone] => 
                                        [address_type] => 
                                    )

                            )

                        [buyer_info] => SellingPartnerApi\Model\OrdersV0\BuyerInfo Object
                            (
                                [container:protected] => Array
                                    (
                                        [buyer_email] => XXXXX@marketplace.amazon.de
                                        [buyer_name] => 
                                        [buyer_county] => 
                                        [buyer_tax_info] => 
                                        [purchase_order_number] => 
                                    )

                            )

                        [automated_shipping_settings] => 
                        [has_regulated_items] => 
                    )

            )

        [errors] => 
        [headers] => Array
            (
                [Date] => Array
                    (
                        [0] => Tue, 30 Aug 2022 16:27:35 GMT
                    )

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

                [Content-Length] => Array
                    (
                        [0] => 977
                    )

                [Connection] => Array
                    (
                        [0] => keep-alive
                    )

                [x-amzn-RequestId] => Array
                    (
                        [0] => 29606bf4-744d-414f-91cd-XXXX
                    )

                [x-amzn-RateLimit-Limit] => Array
                    (
                        [0] => 0.0167
                    )

                [x-amz-apigw-id] => Array
                    (
                        [0] => Xr4SoEfzjXXXXX=
                    )

                [X-Amzn-Trace-Id] => Array
                    (
                        [0] => Root=1-630e3a77-XXXX
                    )

            )

    )

)`

(Please note that I made sensitive data with XX away).

Amazon support says that I already have PII roll and the data I had already received with the old interface MWS as well.

Can you please tell me if it is a bug in my code that I am not getting this data?

2022.09.26 edit: from: $result = $apiInstance->getOrder($order_id); to: $result = $apiInstance->getOrder($order_id, $data_elements);

Result: Problem exists.

KhorneHoly commented 2 years ago

No bug in your code, SP-API doesn't return buyer data via this API even though you have the PII permission. In my contact with the amazon support this should be changed with the next release of the orders API, but I wouldn't bet on it.

We're currently using the GET_ORDER_REPORT_DATA_INVOICING report to get the buyer address.

phploader commented 2 years ago

I received the following response from Amazon on this topic. Unfortunately, I can not quite follow. Could this possibly be due to the code API that is handled incorrectly there with the token?

Please allow me to inform you that the file sent on 19-08-2022 has an access token sent in the request. Calling a restricted operation with an access token will allow you to call an operation, but the PII will not be returned.

Please note: Token starting with Atzr is a refresh token (R for refresh) Token starting with Atza is an access token (A for Access) Token starting with Atz.sprdt is a restricted data token (sprdt could mean Selling Partner Restricted Data Token).

Please feel free to check the attachment, and you will see that the value provided for x-amz-access-token starts with Atza|XXXXX

I would like to request you to please follow the guide provided below to generate a restricted data token, and use that RDT to call any restricted operation.

Please take the time to fully read and understand the document, and if you have questions about it, please feel free to ask: https://developer-docs.amazon.com/sp-api/docs/tokens-api-use-case-guide

@KhorneHoly Otherwise, could you give me a code example of how you retrieve the data via GEZ_ORDER_REPORT_DATA_INVOICING?

gmauro99 commented 2 years ago

@phploader

You forgot to pass the 2nd argument in getOrder, it should be:

$result = $apiInstance->getOrder($order_id, $data_elements);

jlevers commented 2 years ago

@gmauro99 has the correct solution here -- I'm going to close this. @phploader, please feel free to respond to this if you still need help.

phploader commented 2 years ago

Hello, @gmauro99 thanks for the hint, unfortunately this did not bring the solution either. I have changed the line as follows.

$result = $apiInstance->getOrder($order_id, $data_elements);

The output is unfortunately the same without the customer address.

The problem still exists.

@jlevers Can you please open the topic again? The topic is not closed.