Amazon-SP-API-CSharp icon indicating copy to clipboard operation
Amazon-SP-API-CSharp copied to clipboard

Orders.GetOrders() is returning "Empty target resource argument found error" after updating library Version 1.7.2 > 1.7.18

Open smithburger opened this issue 1 year ago • 6 comments

My application was using 1.7.2. I upgraded to 1.7.18 and Orders.GetOrders() stopped working. It is now returning "Empty target resource argument found error" no matter what inputs I give it. I have not had time to dive into this. If I get time and can figure it out I will post here. I wanted to say something now in case you or someone else knows what has changed recently.

I was able to downgrade back to 1.7.2 for now. I tried to downgrade to 1.7.10 to see if I could figure out which update broke it. 1.7.10 threw the error as well. It is somewhere between .2 and .10.

AmazonConnection connection = new AmazonConnection(new AmazonCredential()
{
    AccessKey = ConfigurationManager.AppSettings["accessKey"],
    SecretKey = ConfigurationManager.AppSettings["secretKey"],
    RoleArn = ConfigurationManager.AppSettings["roleARN"],
    ClientId = ConfigurationManager.AppSettings["clientId"],
    ClientSecret = ConfigurationManager.AppSettings["clientSecret"],
    RefreshToken = ConfigurationManager.AppSettings["refreshToken"],
    MarketPlace = MarketPlace.US
});

var parameterOrderList = new ParameterOrderList
{
    CreatedAfter = DateTime.UtcNow.AddHours(-120),
    OrderStatuses = new List<OrderStatuses> { OrderStatuses.Unshipped },
    MarketplaceIds = new List<string> { MarketPlace.US.ID },
    IsNeedRestrictedDataToken = true
};

var amazonOrders = connection.Orders.GetOrders(parameterOrderList);

smithburger avatar Jun 26 '24 18:06 smithburger

I am also experiencing this issue.

I removed the AccessKey, SecretKey and RoleARN as they are no longer required. However, when I set IsNeedRestrictedDataToken to true I get that same message.

When IsNeedRestrictedDataToken is false I do get orders data successfully.

michaelsowa avatar Jun 27 '24 15:06 michaelsowa

Just to confirm - I can accomplish this via Postman without an issue

michaelsowa avatar Jun 27 '24 15:06 michaelsowa

Further update - when I added this:

RestrictedDataTokenRequest = new CreateRestrictedDataTokenRequest { restrictedResources = new List<RestrictedResource> { new RestrictedResource { method = Method.GET.ToString(), path = ApiUrls.OrdersApiUrls.Orders, dataElements = new List<string> { "buyerInfo", "shippingAddress" } } } }

To my params, it works.

michaelsowa avatar Jun 27 '24 15:06 michaelsowa

Unfortunately this is not a complete solution. If the GetOrders call will return > 100 orders then the orders after the first 100 will not have the PII data in. I.e. the first call is fine, but if a NextToken is retuned then the subsequent requests have no PII data returned. I.e. the GetGetOrdersByNextTokenAsync function is not using the RestrictedDataToken

shoecake avatar Aug 27 '24 14:08 shoecake

Was there a fix for this error, as I upgraded ver 1.7.27 today and have the same issue? Thanks

mjw2022 avatar Sep 25 '24 12:09 mjw2022

Was there a fix for this error, as I upgraded ver 1.7.27 today and have the same issue? Thanks

I was able overcome the issue by removing IsNeedRestrictedDataToken = true BUT then get the address by using GetOrderAddress

OrderAddress OrderAddress = amazonConnection.Orders.GetOrderAddress(order.AmazonOrderId);

mjw2022 avatar Oct 01 '24 13:10 mjw2022

Has this bug been fixed? I'm stuck on version 1.7.9, unable to update to a higher version because as soon as I do, this problem appears again.

CarlosAdrianM avatar Oct 30 '24 08:10 CarlosAdrianM

Further update - when I added this:

RestrictedDataTokenRequest = new CreateRestrictedDataTokenRequest { restrictedResources = new List<RestrictedResource> { new RestrictedResource { method = Method.GET.ToString(), path = ApiUrls.OrdersApiUrls.Orders, dataElements = new List<string> { "buyerInfo", "shippingAddress" } } } }

To my params, it works.

Hello brother, have you been able to retrieve the address recently?

ouzhiman avatar Feb 19 '25 03:02 ouzhiman

Was there a fix for this error, as I upgraded ver 1.7.27 today and have the same issue? Thanks

I was able overcome the issue by removing IsNeedRestrictedDataToken = true BUT then get the address by using GetOrderAddress

OrderAddress OrderAddress = amazonConnection.Orders.GetOrderAddress(order.AmazonOrderId);

Hello brother, have you been able to retrieve the address recently?

ouzhiman avatar Feb 19 '25 03:02 ouzhiman

Was there a fix for this error, as I upgraded ver 1.7.27 today and have the same issue? Thanks

I was able overcome the issue by removing IsNeedRestrictedDataToken = true BUT then get the address by using GetOrderAddress OrderAddress OrderAddress = amazonConnection.Orders.GetOrderAddress(order.AmazonOrderId);

Hello brother, have you been able to retrieve the address recently?

The most similar to a workaround is:

            var conexion = AmazonApiOrdersService.ConexionAmazon();
            var orders = await conexion.Orders.GetOrdersAsync(searchOrderList).ConfigureAwait(false);
            foreach (var orderAdresss in orders)
            {
                var address = await conexion.Orders.GetOrderAddressAsync(orderAdresss.AmazonOrderId).ConfigureAwait(false);
                orderAdresss.ShippingAddress = address.ShippingAddress;
            }
            return orders;

CarlosAdrianM avatar Feb 20 '25 08:02 CarlosAdrianM

The most similar to a workaround is:

            var conexion = AmazonApiOrdersService.ConexionAmazon();
            var orders = await conexion.Orders.GetOrdersAsync(searchOrderList).ConfigureAwait(false);
            foreach (var orderAdresss in orders)
            {
                var address = await conexion.Orders.GetOrderAddressAsync(orderAdresss.AmazonOrderId).ConfigureAwait(false);
                orderAdresss.ShippingAddress = address.ShippingAddress;
            }
            return orders;

This is the best solution when there is > than 100 orders. For the first 100 orders you can manually add the Restricted Data Token:

RestrictedDataTokenRequest = new CreateRestrictedDataTokenRequest { restrictedResources = new List<RestrictedResource> { new RestrictedResource { method = Method.GET.ToString(), path = ApiUrls.OrdersApiUrls.Orders, dataElements = new List { "buyerInfo", "shippingAddress" } } } }

It is the GetGetOrdersByNextTokenAsync function which does not use the RestrictedDataToken

shoecake avatar Feb 20 '25 09:02 shoecake

@abuzuhri can we please get a fix of this error? I updated to 1.8.1 Version and starting getting this error.

qaisarikram avatar Mar 25 '25 19:03 qaisarikram

Having the same issue. Buyers information isn't populating either when passing "buyerInfo" to the dataelements for restricted resource.

PoeticArcher avatar May 24 '25 00:05 PoeticArcher

I need help from some one with access token for testing for if some one can solve it and submit the change to merge

abuzuhri avatar Jul 01 '25 17:07 abuzuhri