Heilyn
Heilyn

Reputation: 61

How to update an amazon order status to Shipped using MWS

I'm new in amazon MWS, i have the order number, and I need to update the order as Shipped in Amazon, i have read that we can do it using SubmitFeed Api, I have a reference in my project to MWSOrders_2013-09-01_v2013-09-01.dll but i dont have access to SubmitFeed,please could anybody give me an idea of how my code should be?

Upvotes: 3

Views: 1941

Answers (3)

Heilyn
Heilyn

Reputation: 61

finally here is my vb.net code, it is working properly.

Public Function UpdateOrderStatusInAmazonWebSite(ByRef AmazonEntity As NSAmazonEntity, ByVal amazonOrder As NSAmazonMWSOrder) As SubmitFeedResponse
Dim response As SubmitFeedResponse Try

        ''get ftnorder data
        Dim entity As New NSWebUtilityEntities
        Dim ftnOrder = (From f In entity.FTNFTPOrders Where f.PONum = amazonOrder.AmazonOrderID And f.SalesOrderNum = amazonOrder.GPOrderNumber Select f).ToList()(0)
        Dim fulfillmentdata As New NSAmazonFulfillmentData()
        Dim carrier As Integer = (From s In entity.ShippingMethods Where s.ShippingMethodId = ftnOrder.ShippingMethodId Select s.CarrierId).ToList()(0)
        fulfillmentdata.CarrierCode = (From c In entity.Carriers Where c.CarrierId = carrier Select c.Code).ToList()(0)
        fulfillmentdata.CarrierName = (From c In entity.Carriers Where c.CarrierId = carrier Select c.Description).ToList()(0)
        fulfillmentdata.ShipperTrackingNumber = ftnOrder.Tracking1
        fulfillmentdata.ShippingMethod = (From s In entity.ShippingMethods Where s.ShippingMethodId = ftnOrder.ShippingMethodId Select s.Name).ToList()(0)


        Dim appName As String = "CSharpSampleCode"  
        Dim appVersion As String = "1.0"        
        Dim serviceURL As String = "https://mws.amazonservices.com"     
        Dim accessKeyId As String = AmazonEntity.AccessKey
        Dim secretAccessKey As String = AmazonEntity.SecretKey
        Dim sellerid As String = AmazonEntity.SellerID
        Dim config As New MarketplaceWebService.MarketplaceWebServiceConfig
        config.ServiceURL = serviceURL

        Dim service As New MarketplaceWebService.MarketplaceWebServiceClient(
                accessKeyId,
                secretAccessKey,
                appName,
                appVersion,
                config)

        '----create and write XML file
        Dim pre_message As String = ""
        pre_message = pre_message + "<Message>"
        pre_message = pre_message + "<MessageID>" + "1" + "</MessageID>"
        pre_message = pre_message + "<OrderFulfillment>"
        pre_message = pre_message + "<AmazonOrderID>" + amazonOrder.AmazonOrderID + "</AmazonOrderID>"
        Dim dd As DateTime = ftnOrder.ShipDt
        pre_message = pre_message + "<FulfillmentDate>" + dd.ToUniversalTime + "</FulfillmentDate>"
        pre_message = pre_message + "<FulfillmentData>"
        pre_message = pre_message + "<CarrierCode>" + fulfillmentdata.CarrierCode + "</CarrierCode>"
        pre_message = pre_message + "<ShippingMethod>" + fulfillmentdata.ShippingMethod + "</ShippingMethod>"
        pre_message = pre_message + "<ShipperTrackingNumber>" + fulfillmentdata.ShipperTrackingNumber + "</ShipperTrackingNumber>"
        pre_message = pre_message + "</FulfillmentData>"
        pre_message = pre_message + "</OrderFulfillment>"
        pre_message = pre_message + "<Item>"
        pre_message = pre_message + "<AmazonOrderItemCode>" + amazonOrder.OrderItems(0).OrderItemId + "</AmazonOrderItemCode>"
        pre_message = pre_message + "<Quantity>1</Quantity>"
        pre_message = pre_message + "</Item>"
        pre_message = pre_message + "</Message>"

        Dim feed As String = ""
        feed = feed + "<?xml version='1.0'?>"
        feed = feed + "<AmazonEnvelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='amzn-envelope.xsd'> "
        feed = feed + "<Header>"
        feed = feed + "<DocumentVersion>1.01</DocumentVersion>"
        feed = feed + "<MerchantIdentifier>" + sellerid + "</MerchantIdentifier>"
        feed = feed + "</Header>"
        feed = feed + "<MessageType>OrderFulfillment</MessageType>"
        feed = feed + pre_message
        feed = feed + "</AmazonEnvelope>"
        feed.Trim()

        Dim myPath As String = AppDomain.CurrentDomain.BaseDirectory + "\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "tmp.xml"

        If File.Exists(myPath) Then
            File.Delete(myPath)
        ElseIf Not File.Exists(myPath) Then
            ' Create a file to write to.
            Dim sw As StreamWriter = File.CreateText(myPath)
            sw.Write(feed)
            sw.Close()
        End If
        Dim request As New SubmitFeedRequest()
        request.Merchant = sellerid
        request.MarketplaceIdList = New IdList()
        Dim m As New List(Of String)
        m.Add(AmazonEntity.MarketPlaceID)
        request.MarketplaceIdList.Id = New List(Of String)
        request.MarketplaceIdList.Id = m
        request.FeedContent = File.Open(myPath, FileMode.Open, FileAccess.Read)
        request.ContentMD5 = MarketplaceWebService.MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent)
        request.FeedContent.Position = 0
        request.PurgeAndReplace = False
        request.FeedType = "_POST_ORDER_FULFILLMENT_DATA_"

        response = service.SubmitFeed(request)

    Catch ex As MarketplaceWebService.MarketplaceWebServiceException
        ' Exception properties are important for diagnostics.
    Catch ex2 As Exception

    End Try

    Return response

End Function

Upvotes: 2

ScottG
ScottG

Reputation: 11121

I'm going to guess you're a C# programmer based on your question, although you don't say what library/platform you're using. You say you have the MWS dll, but everything you need is contained within it, so maybe you don't have the right thing. Amazon has everything you need to get started and submit a feed in minutes, just download the C# client library right here: https://developer.amazonservices.com/doc/bde/feeds/v20090101/cSharp.html/175-9415024-6151568

Extract the src folder, open in Visual Studio and everything is there including the client libraries along with example code. In your case, look in the MarkletplaceWebService.Samples project for MarketplaceWebServiceSamples.cs file. Fill in your access keys and then search for SubmitFeed. Uncomment and fill in what you need for your request and run it.

If you're not a C# programmer, have a look at the other client libraries. It really is easy to get started. https://developer.amazonservices.com/gp/mws/api.html/175-9415024-6151568?ie=UTF8&group=bde&section=feeds&version=latest

Upvotes: 0

mcdonagg
mcdonagg

Reputation: 94

I would like to know a bit more information to answer the question but if you are looking just for the XML layout of how to do it you can refrence Selling on Amazon Guide to XML

basically the layout is:

<xsd:complexType>
<xsd:sequence>
<xsd:element ref="AmazonOrderID"/>
<xsd:element ref="MerchantOrderID" minOccurs="0"/>
<xsd:element name="StatusCode">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Success"/>
<xsd:enumeration value="Failure"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Item" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="AmazonOrderItemCode"/>
<xsd:element ref="MerchantOrderItemID" minOccurs="0"/>
<xsd:element name="CancelReason" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="NoInventory"/>
<xsd:enumeration value="ShippingAddressUndeliverable"/>
<xsd:enumeration value="CustomerExchange"/>
<xsd:enumeration value="BuyerCanceled"/>
<xsd:enumeration value="GeneralAdjustment"/>
<xsd:enumeration value="CarrierCreditDecision"/>
<xsd:enumeration value="RiskAssessmentInformationNotValid"/>
<xsd:enumeration value="CarrierCoverageFailure"/>
<xsd:enumeration value="CustomerReturn"/>
<xsd:enumeration value="MerchandiseNotReceived"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

and here is an example:

<?xml version="1.0"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
 <DocumentVersion>1.01</DocumentVersion>
 <MerchantIdentifier> M_IDENTIFIER</MerchantIdentifier>
</Header>
<MessageType>OrderAcknowledgement</MessageType>
<Message>
 <MessageID>1</MessageID>
 <OrderAcknowledgement>
 <AmazonOrderID>050-1234567-1234567</AmazonOrderID>
 <MerchantOrderID>1234567</MerchantOrderID>
 <StatusCode>Success</StatusCode>
 <Item>
 <AmazonOrderItemCode>12345678901234</AmazonOrderItemCode>
 <MerchantOrderItemID>1234567</MerchantOrderItemID>
 </Item>
 </OrderAcknowledgement>
</Message>
</AmazonEnvelope> 

I am using Ruby on Rails to write my application that does this. So if you are too you can look at Gem Peddler to interact with the api and I also use Nokogiri (which you can google since I am not cool enough to post more than 2 links :) to create the xml. If you would like I can share my code but it is rather particular to me and to Ruby on Rail.

Upvotes: 2

Related Questions