amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
580 stars 730 forks source link

[BUG] POST_ORDER_FULFILLMENT_DATA ill-formed #1758

Closed joevu-stlpro closed 3 years ago

joevu-stlpro commented 3 years ago

Hi There,

I have troubles with ill-formed POST_ORDER_FULFILLMENT_DATA feed. I do validate my xml content with the xsd file.

The input xml data that I sent

<?xml version="1.0" encoding="utf-8"?>
<OrderFulfillment xsi:noNamespaceSchemaLocation="OrderFulfillment.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <AmazonOrderID>**********</AmazonOrderID>
  <FulfillmentDate>2021-08-16T14:35:28.831329+00:00</FulfillmentDate>
  <FulfillmentData>
    <CarrierCode>FedEx</CarrierCode>
    <CarrierName>FedEx</CarrierName>
    <ShippingMethod></ShippingMethod>
    <ShipperTrackingNumber>*********</ShipperTrackingNumber>
  </FulfillmentData>
  <Item>
    <AmazonOrderItemCode>********</AmazonOrderItemCode>
    <Quantity>1</Quantity>
  </Item>
</OrderFulfillment>

The response I got from Amazon SP API

<?xml version="1.0" encoding="UTF-8"?>
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    <Header>
        <DocumentVersion>1.02</DocumentVersion>
        <MerchantIdentifier>****</MerchantIdentifier>
    </Header>
    <MessageType>ProcessingReport</MessageType>
    <Message>
        <MessageID>1</MessageID>
        <ProcessingReport>
            <DocumentTransactionID>54188018855</DocumentTransactionID>
            <StatusCode>Complete</StatusCode>
            <ProcessingSummary>
                <MessagesProcessed>0</MessagesProcessed>
                <MessagesSuccessful>0</MessagesSuccessful>
                <MessagesWithError>1</MessagesWithError>
                <MessagesWithWarning>0</MessagesWithWarning>
            </ProcessingSummary>
            <Result>
                <MessageID>9223372036854775807</MessageID>
                <ResultCode>Error</ResultCode>
                <ResultMessageCode>50001</ResultMessageCode>
                <ResultDescription>The XML you submitted is ill-formed at the Amazon Envelope XML level at (or near) line 2, column 6.</ResultDescription>
            </Result>
        </ProcessingReport>
    </Message>
</AmazonEnvelope>
chenlixin93 commented 3 years ago

@joevu-stlpro https://github.com/amzn/selling-partner-api-models/issues/1746

Hope it helps.

joevu-stlpro commented 3 years ago

thanks @chenlixin93 however, when I tried the api version 2021-06-30, for the api Create Feed Document, the response does not contain the key encryptionDetails (only 2 keys feedDocumentId and url) in order to encrypt file on uploading, then it fails to upload feed content to the feed document.

While the old version 2020-09-04 does contain the field encryptionDetails.

To be honest, the document is inconsistent and 100% cover all needed materials for SELLERs.

I am also looking for the feed type request/response POST_FLAT_FILE_INVLOADER_DATA, however, there is no specification (no .xsd file) in this feedtype-values document

chenlixin93 commented 3 years ago

@joevu-stlpro

joevu-stlpro commented 3 years ago

Thanks a ton @chenlixin93

I have resolved my problem, just wanna share how it works in both versions.

I use the python package: https://github.com/saleweaver/python-amazon-sp-api/

Version 2020-09-04

I install the package python-amazon-sp-api, and use the old MWS feed message

<?xml version="1.0" encoding="UTF-8"?>
        <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Header>
                <DocumentVersion>1.01</DocumentVersion>
                <MerchantIdentifier>None</MerchantIdentifier>
            </Header>
            <MessageType>OrderFulfillment</MessageType>

        <Message>
            <MessageID>1</MessageID>
            <OrderFulfillment>
                <AmazonOrderID>--------</AmazonOrderID>
                <FulfillmentDate>2021-08-20T02:35:31.312036+00:00</FulfillmentDate>
                <FulfillmentData>
                    <CarrierCode>--------</CarrierCode>
                    <ShippingMethod>--------</ShippingMethod>
                    <ShipperTrackingNumber>--------</ShipperTrackingNumber>
                </FulfillmentData>
                <Item>
                    <AmazonOrderItemCode>--------</AmazonOrderItemCode>
                    <Quantity>1</Quantity>
                </Item>
            </OrderFulfillment>
        </Message>
        </AmazonEnvelope>

the code snippet is

import io
from sp_api.api import Feeds

credentials = {
    'refresh_token': '***',
    'lwa_app_id': '***',
    'lwa_client_secret': '***',
    'aws_access_key': '***',
    'aws_secret_key': '***',
    'role_arn': '***'
}

feeds_client = Feeds(credentials=credentials)

feed_content = '''<?xml version="1.0" encoding="UTF-8"?>
        <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Header>
                <DocumentVersion>1.01</DocumentVersion>
                <MerchantIdentifier>None</MerchantIdentifier>
            </Header>
            <MessageType>OrderFulfillment</MessageType>

        <Message>
            <MessageID>1</MessageID>
            <OrderFulfillment>
                <AmazonOrderID>order-id</AmazonOrderID>
                <FulfillmentDate>2021-08-20T02:35:31.312036+00:00</FulfillmentDate>
                <FulfillmentData>
                    <CarrierCode>carrier-code</CarrierCode>
                    <ShippingMethod>shipping method</ShippingMethod>
                    <ShipperTrackingNumber>tracking id</ShipperTrackingNumber>
                </FulfillmentData>
                <Item>
                    <AmazonOrderItemCode>order-item-id</AmazonOrderItemCode>
                    <Quantity>1</Quantity>
                </Item>
            </OrderFulfillment>
        </Message>
        </AmazonEnvelope>
'''

feed_file = io.StringIO(feed_content)
feed_type = 'POST_ORDER_FULFILLMENT_DATA'
response = feeds_client.create_feed_document(feed_file)

document_id = response.payload['feedDocumentId']
response = feeds_client.create_feed(feed_type, document_id)
feed_id = response.payload['feedId']

# You have to wait for few seconds for feed processing.
# Then when you get feed, it will show Feed Document ID

feed_response = feeds_client.get_feed(feed_id)
print(feed_response)

feed_result_document_id = feed_response['resultFeedDocumentId']
feed_result_response = feeds_client.get_feed_result_document(feed_result_document_id)
print(feed_result_response)

# If you see your message is success => you are done.

Version 2021-06-30

For this version, you gotta wait for few days/weeks for the author to update that, or you can go ahead to custom the class sp_api/api/feeds/feeds.py so it can use the version 2021-06-31. This is pretty simple.

yingyuhaonan commented 2 years ago

Thanks a ton @chenlixin93

I have resolved my problem, just wanna share how it works in both versions.

I use the python package: https://github.com/saleweaver/python-amazon-sp-api/

Version 2020-09-04

I install the package python-amazon-sp-api, and use the old MWS feed message

<?xml version="1.0" encoding="UTF-8"?>
        <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Header>
                <DocumentVersion>1.01</DocumentVersion>
                <MerchantIdentifier>None</MerchantIdentifier>
            </Header>
            <MessageType>OrderFulfillment</MessageType>

        <Message>
            <MessageID>1</MessageID>
            <OrderFulfillment>
                <AmazonOrderID>--------</AmazonOrderID>
                <FulfillmentDate>2021-08-20T02:35:31.312036+00:00</FulfillmentDate>
                <FulfillmentData>
                    <CarrierCode>--------</CarrierCode>
                    <ShippingMethod>--------</ShippingMethod>
                    <ShipperTrackingNumber>--------</ShipperTrackingNumber>
                </FulfillmentData>
                <Item>
                    <AmazonOrderItemCode>--------</AmazonOrderItemCode>
                    <Quantity>1</Quantity>
                </Item>
            </OrderFulfillment>
        </Message>
        </AmazonEnvelope>

the code snippet is

import io
from sp_api.api import Feeds

credentials = {
    'refresh_token': '***',
    'lwa_app_id': '***',
    'lwa_client_secret': '***',
    'aws_access_key': '***',
    'aws_secret_key': '***',
    'role_arn': '***'
}

feeds_client = Feeds(credentials=credentials)

feed_content = '''<?xml version="1.0" encoding="UTF-8"?>
        <AmazonEnvelope xsi:noNamespaceSchemaLocation="amzn-envelope.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Header>
                <DocumentVersion>1.01</DocumentVersion>
                <MerchantIdentifier>None</MerchantIdentifier>
            </Header>
            <MessageType>OrderFulfillment</MessageType>

        <Message>
            <MessageID>1</MessageID>
            <OrderFulfillment>
                <AmazonOrderID>order-id</AmazonOrderID>
                <FulfillmentDate>2021-08-20T02:35:31.312036+00:00</FulfillmentDate>
                <FulfillmentData>
                    <CarrierCode>carrier-code</CarrierCode>
                    <ShippingMethod>shipping method</ShippingMethod>
                    <ShipperTrackingNumber>tracking id</ShipperTrackingNumber>
                </FulfillmentData>
                <Item>
                    <AmazonOrderItemCode>order-item-id</AmazonOrderItemCode>
                    <Quantity>1</Quantity>
                </Item>
            </OrderFulfillment>
        </Message>
        </AmazonEnvelope>
'''

feed_file = io.StringIO(feed_content)
feed_type = 'POST_ORDER_FULFILLMENT_DATA'
response = feeds_client.create_feed_document(feed_file)

document_id = response.payload['feedDocumentId']
response = feeds_client.create_feed(feed_type, document_id)
feed_id = response.payload['feedId']

# You have to wait for few seconds for feed processing.
# Then when you get feed, it will show Feed Document ID

feed_response = feeds_client.get_feed(feed_id)
print(feed_response)

feed_result_document_id = feed_response['resultFeedDocumentId']
feed_result_response = feeds_client.get_feed_result_document(feed_result_document_id)
print(feed_result_response)

# If you see your message is success => you are done.

Version 2021-06-30

For this version, you gotta wait for few days/weeks for the author to update that, or you can go ahead to custom the class sp_api/api/feeds/feeds.py so it can use the version 2021-06-31. This is pretty simple

yingyuhaonan commented 2 years ago

@joevu-stlpro

大佬,我这边标记发货有时成功有时失败,失败时大多的错误为

We are unable to process the XML feed because one or more items are invalid. Please re-submit the feed. --

,可以帮一下我么

chenlixin93 commented 2 years ago

@yingyuhaonan 我的邮箱是 chenlixin93@gmail.com,可以的话在邮件里把问题描述下,最好是有相关代码和截图,也可以附上你的QQ方便联系。

yingyuhaonan commented 2 years ago

@yingyuhaonan 我的邮箱是 chenlixin93@gmail.com,可以的话在邮件里把问题描述下,最好是有相关代码和截图,也可以附上你的QQ方便联系。

我的QQ 1242338047

chenlixin93 commented 2 years ago

@yingyuhaonan 可以看看我上面提到的 https://github.com/amzn/selling-partner-api-models/issues/1746 ,印象里api版本换到 21-06-30 就没什么问题了。