abuzuhri / Amazon-SP-API-CSharp

.Net C# library for the new Amazon Selling Partner API
MIT License
217 stars 191 forks source link

Getting getting LWA Access Token Error while posting Shipment tracking on amazon #727

Open asifiq2000 opened 7 months ago

asifiq2000 commented 7 months ago

Hi @abuzuhri,

I am using the SP-API shipping tracking using the FIKA API

POST_ORDER_FULFILLMENT_DATA method to post the shipment on amazon but it is throwing below mentioned error, kindly suggest.

Error Detail: Exception has occurred: CLR/System.SystemException An exception of type 'System.SystemException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Error getting LWA Access Token' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.IO.IOException : Unsuccessful LWA token exchange at FikaAmazonAPI.AmazonSpApiSDK.Runtime.LWAClient.d__15.MoveNext()


code detail:

public String PostAmazonShipmentTracking(string mRefreshToken, string mSellerID, string mAmazonOrderID, string mCarrierName, string mShippingMethod, string mShipperTrackingNumber, string mCarrierCode, string mClientId, string mClientSecret) { //MarketPlace = MarketPlace.GetMarketPlaceByID("ATVPDKIKX0DER"), AmazonConnection amazonConnection = new AmazonConnection(new AmazonCredential() { AccessKey = "XXX", SecretKey = "XXX", RoleArn = "XXX", ClientId = mClientId, ClientSecret = mClientSecret, RefreshToken = mRefreshToken, MarketPlace = MarketPlace.GetMarketPlaceByID(mSellerID), });

        ConstructFeedService createDocument = new ConstructFeedService(mSellerID, "1.02");
        var list = new List<OrderFulfillmentMessage>();

            list.Add(new OrderFulfillmentMessage()
            {
                AmazonOrderID = mAmazonOrderID,
                //FulfillmentDate = DateTime.UtcNow.ToString(),
                FulfillmentDate = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK"),
                FulfillmentData = new FulfillmentData()
                {
                    CarrierCode = mCarrierName,
                    CarrierName = mCarrierName,
                    ShippingMethod = mShippingMethod,
                    ShipperTrackingNumber = mShipperTrackingNumber
                }
            });

        createDocument.AddOrderFulfillmentMessage(list);

        var xml = createDocument.GetXML();

        string feedID = amazonConnection.Feed.SubmitFeed(xml, FeedType.POST_ORDER_FULFILLMENT_DATA);

image_2024_04_15T03_21_23_957Z

ismkdc commented 7 months ago

same problem i have

kevinvenclovas commented 7 months ago

@ismkdc @asifiq2000 Hey, i think there is a problem with your credentials.

Try to remove the AccessKey, SecretKeyand RoleArnfrom your AmazonCredential, with the refreshtoken you need this information anymore and check your ClientId,ClientSecretand RefresTokenagain.

new AmazonCredential()
{
    ClientId = 'XXX',
    ClientSecret = 'XXX',
    RefreshToken = 'XXX',
    MarketPlace = MarketPlace.Germany
};

You can also try to remove CarrierName and ShippingMethod from FulfillmentData. I used it like this without any issues.

list.Add(new OrderFulfillmentMessage()
{
    AmazonOrderID = order.AmazonOrderId,
    FulfillmentDate = order.ShippingTime,
    FulfillmentData = new FulfillmentData()
    {
        CarrierCode = order.Carrier,
        ShipperTrackingNumber = order.Trackingnumber,
    }
});
asifiq2000 commented 1 week ago

Hi @abuzuhri

I have implemented the POST_ORDER_FULFILLMENT_DATA API posting through FIKA First I send the tracking detail on amazon through FIKA using below method

createDocument.AddOrderFulfillmentMessage(list); var xml = createDocument.GetXML(); string feedID = amazonConnection.Feed.SubmitFeed(xml, FeedType.POST_ORDER_FULFILLMENT_DATA);

which is running fine, but when I Post the tracking through SubmitFeed() method as mentioned above I get the FeedID from amazon then I make a new request to get the Status of that FeedID through the below method:

feedOutput=amazonConnection.Feed.GetFeed(mFeedID); if(feedOutput.ResultFeedDocumentId is not null) { var outPut=amazonConnection.Feed.GetFeedDocument(feedOutput.ResultFeedDocumentId); if (outPut is not null) { var processingReport = amazonConnection.Feed.GetFeedDocumentProcessingReport(outPut.Url); resultCatalogFeed.FeedSubbmisionID = processingReport.DocumentTransactionID; resultCatalogFeed.TotalProductSubmited = Convert.ToInt32(processingReport.ProcessingSummary.MessagesProcessed); resultCatalogFeed.SuccessCount = Convert.ToInt32(processingReport.ProcessingSummary.MessagesSuccessful); resultCatalogFeed.ErrorCount = Convert.ToInt32(processingReport.ProcessingSummary.MessagesWithError); resultCatalogFeed.StatusCode = processingReport.StatusCode; }} then I am getting the posting date but not getting the posting date with Time since our client complaining about the delay in tracking update on amazon, I am unable to find out the update time in our system, coz status response does not have that, so please help me how to get that detail. Is anything wrong I am doing in this, please suggest. Kindly help me ASAP, Its urgent, Thanks in Advance

Note: Our client asked me to create support ticket on amazon that why we are not getting the tracking update time in response so amazon asking us to provide all the request details url, endpoint, parameters, headers, and payload then they will check and answer our query.