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

[BUG] [SP-API] C# SDK 2.0 No PII (Shipping Address) Returned by GetOrders or RDT Error #459

Closed
dathat opened this issue Oct 19, 2023 · 4 comments
Labels
bug Something isn't working closing soon

Comments

@dathat
Copy link

dathat commented Oct 19, 2023

I'm submitting a...

[x] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[x] Documentation issue or request
[ ] Other... Please describe:

SP-API Name and Version or Report/Feed Type

API: ordersV0 API using the new C# SDK 2.0 released about a week ago. Calling getOrders to retrieve a list of orders.

Expected Behavior

Previously with the C# SDK 1.0 I set a RDT with data elements "buyerInfo" and "shippingAddress" and shipping information would be returned by GetOrders. Psuedo code:

OrdersV0Api ordersApi = new OrdersV0Api.Builder()
    .SetAWSAuthenticationCredentials(AmazonTokens.awsAuthenticationCredentials)
    .SetLWAAuthorizationCredentials(AmazonTokens.lwaAuthorizationCredentials)
    .Build();

TokensApi tokensApi = new TokensApi.Builder()
    .SetAWSAuthenticationCredentials(AmazonTokens.awsAuthenticationCredentials)
    .SetLWAAuthorizationCredentials(AmazonTokens.lwaAuthorizationCredentials)
    .Build();

List<RestrictedResource> restrictedResourceList = new List<RestrictedResource>();
List<string> dataElements = new List<string>
{
    "buyerInfo",
    "shippingAddress"
};
restrictedResourceList.Add(new RestrictedResource(RestrictedResource.MethodEnum.GET, "/orders/v0/orders", dataElements));
CreateRestrictedDataTokenRequest createRDT = new CreateRestrictedDataTokenRequest(null, restrictedResourceList);
CreateRestrictedDataTokenResponse rdtResponse = tokensApi.CreateRestrictedDataToken(createRDT);

ordersApi.Configuration.AddDefaultHeader("x-amz-access-token", rdtResponse.RestrictedDataToken);

GetOrdersResponse response = ordersApi.GetOrders(marketplaceIds, null, null, null, null, null, null, null, null, null, maxResultsPerPage, null, null, null, orderIDs, null, null, null, null, null);

Current Behavior

After regenerating all the DLLs with the newer 2.0 SDK if I generate and attach a RDT the same way as previously I get the error: {"code": "Unauthorized", "message": "Access to requested resource is denied.", "details": "The access token you provided is revoked, malformed or invalid."}

If I do not generate or attach a RDT the PII shipping information is not returned. It seems like the new SDK automatically creates RDTs as needed since I can call GetOrderAddress without generating or attaching a RDT using the 2.0 SDK and the shipping information is returned, However, this would not work well since it would require an extra call for every order. Psuedo code:

OrdersV0Api ordersApi = new OrdersV0Api.Builder()
    .SetLWAAuthorizationCredentials(AmazonTokens.lwaAuthorizationCredentials)
    .Build();

GetOrdersResponse response = ordersApi.GetOrders(marketplaceIds, null, null, null, null, null, null, null, null, null, maxResultsPerPage, null, null, null, orderIDs, null, null, null, null, null);

foreach (Order order in response.Payload.Orders)
{
    GetOrderAddressResponse orderAddress = ordersApi.GetOrderAddress(order.AmazonOrderId);
}

Context/Screenshots

The use case guide shows shipping information being returned without setting anything to retrieve it (https://developer-docs.amazon.com/sp-api/docs/orders-api-v0-use-case-guide). I am generally confused around the RDT usage now since it seems the newer SDK no longer requires manually generating or setting them. Is there a way to specify "dataElements" for the getOrders call?

Your Environment

Visual Studio Community 2022. Generated Amazon.SellingPartnerAPIAA.dll C# SDK 2.0 with swagger-codegen-cli-2.4.33.jar and using libraries: tokens_2021-03-01, ordersV0

@dathat dathat added the bug Something isn't working label Oct 19, 2023
@dathat
Copy link
Author

dathat commented Oct 20, 2023

Found the solution. I forgot the original C# SDK was broken and Amazon has not fixed it yet. Still have to edit "ApiClient.cs" for each API before generating the DLLs by replacing:

private void InterceptRequest(IRestRequest request)
{
    lwaAuthorizationSigner.Sign(request);
}

with:

private void InterceptRequest(IRestRequest request)
{
    if (!Configuration.DefaultHeader.ContainsKey("x-amz-access-token"))
    {
        lwaAuthorizationSigner.Sign(request);
    }
}

Otherwise the manually added RDT header gets overwritten just before the request is sent to Amazon.

Amazon devs, please fix this. Applying an RDT in place of the LWA signature should not be so confusing. The thread that helped me solve this same issue twice now was started in 2021: #1255

@surkaa
Copy link

surkaa commented Mar 26, 2024

the idea is good!

@shreeharsh-a shreeharsh-a transferred this issue from amzn/selling-partner-api-docs May 9, 2024
Copy link

This is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue after the latest release and if you find that this is still a problem, please feel free to open a new issue and make a reference to this one.

Copy link

closed for inactivity

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closing soon
Projects
None yet
Development

No branches or pull requests

2 participants