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

getOrderBuyerInfo() return 400 Could not match input arguments #500

Closed suffian-farooq closed 1 year ago

suffian-farooq commented 1 year ago

Problem description: getOrders() work fine but getOrderBuyerInfo() not working i don't know how to fix it can anyone help me

Error:

Exception when calling OrdersV0Api->getOrders: [400] [{"code":"InvalidInput","message":"Could not match input arguments"}]

Code


require_once(__DIR__ . '/vendor/autoload.php');

use SellingPartnerApi\Api\SellersV1Api as SellersApi;
use SellingPartnerApi\Configuration;
use SellingPartnerApi\Endpoint;

$config = new Configuration([
    "lwaClientId" => "-----------------------",
    "lwaClientSecret" => "------------------------------------",
    "lwaRefreshToken" => "--------------------------",
    "awsAccessKeyId" => "--------------------",
    "awsSecretAccessKey" => "---------------------------------",
    "endpoint" => Endpoint::NA_SANDBOX,
]);

$config->setDebug(true);
$config->setDebugFile('debug.log');

$orderId = 'TEST_CASE_200';

$apiInstance = new SellingPartnerApi\Api\OrdersV0Api($config);

try {
    $getOrderBuyerInfo = $apiInstance->getOrderBuyerInfo($orderId);
    echo "<pre>";
    //print_r($result2);
     print_r($getOrderBuyerInfo);
    echo "</pre>";

} catch (Exception $e) { 
    echo 'Exception when calling OrdersV0Api->getOrders: ', $e->getMessage(), PHP_EOL;
} 

Seller Central SP API config page screenshot

jlevers commented 1 year ago

That endpoint is deprecated, please use the getOrders endpoint with the $data_elements parameter set to ['buyerInfo'] to retrieve buyer tax information. You need to have access to one or both of the restricted Tax Remittance and Tax Invoicing roles in order to be able to retrieve buyer-related PII.

suffian-farooq commented 1 year ago

@jlevers Thank you for your reply I want billing and shipping information but the billing information is missing in order.

$apiInstance = new SellingPartnerApi\Api\OrdersV0Api($config);
$marketplace_ids = array('ATVPDKIKX0DER'); 
$created_after = 'TEST_CASE_200'; 
$created_before = null; 
$last_updated_after = null; 
$last_updated_before = null; 
$order_statuses = array('Unshipped'); 
$fulfillment_channels = array('');
$payment_methods = array('');
$buyer_email = null; 
$seller_order_id = null;
$max_results_per_page = 56; 
$easy_ship_shipment_statuses = array('');
$electronic_invoice_statuses = array('');
$next_token = null;
$amazon_order_ids = array('');
$actual_fulfillment_supply_source_id = null;
$is_ispu = true; 
$store_chain_store_id = null;
$data_elements = array('buyerInfo'); 

try {
$result = $apiInstance->getOrders( $marketplace_ids, $created_after, $created_before, $last_updated_after, $last_updated_before, $order_statuses, $fulfillment_channels, $payment_methods, $buyer_email, $seller_order_id, $max_results_per_page, $easy_ship_shipment_statuses, $electronic_invoice_statuses, $next_token, $amazon_order_ids, $actual_fulfillment_supply_source_id, $is_ispu, $store_chain_store_id, $data_elements );

    echo "<pre>";
    print_r($result );
    echo "</pre>";
} catch (Exception $e) { 
    echo 'Exception when calling OrdersV0Api->getOrders: ', $e->getMessage(), PHP_EOL;
} 

if I set $data_elements = array('buyerInfo'); it will return 400 if the array is null it works fine. how can I get billing information?

jlevers commented 1 year ago

From my last response:

You need to have access to one or both of the restricted Tax Remittance and Tax Invoicing roles in order to be able to retrieve buyer-related PII.

See more about restricted roles here.