• 亚马逊 sp-api更新库存 feed 方式,xsd 验证xml


    更新库存遇到的坑,  xml格式不对,因为输出的测试xml ,后面又加了点字符串,因为这个错误,耽误我好几天。。。下次测试结果时候,一定要等变量完全停止定义的后面 输出

    1. if($debug) echo htmlentities($xml);
    2. $feedContents = $xml;
    3. // 原来这个多了一行,导致了错误
    4. //$xml .= '';

    feed 更新方式

    1,createFeedDocument 返回 

    feedDocumentId

    (

    POST_INVENTORY_AVAILABILITY_DATA

    )

    2. uploadxml

    3 createfeed

    检测方式

    1 getFeed

    getFeedDocument

    3 根据返回的url ,打开这个网址 看feed的执行结果

    说明1 。inventory 的xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
    3. <Header>
    4. <DocumentVersion>1.01</DocumentVersion>
    5. <MerchantIdentifier>A。。。。。。X</MerchantIdentifier>
    6. </Header>
    7. <MessageType>Inventory</MessageType>
    8. <Message>
    9. <MessageID>1</MessageID>
    10. <OperationType>Update</OperationType>
    11. <Inventory>
    12. <SKU>SY...</SKU>
    13. <FulfillmentCenterID>DEFAULT</FulfillmentCenterID>
    14. <Quantity>3</Quantity>
    15. </Inventory>
    16. </Message>
    17. </AmazonEnvelope>

    2 xsd的位置

    https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Inventory.xsd
    
    
    
    https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/amzn-envelope.xsd
    

    3 根据xsd 判断xml是否符合格式

    https://www.freeformatter.com/xml-validator-xsd.html

    最后演示代码

    1. use SellingPartnerApi\Api\FeedsV20210630Api as FeedsApi;
    2. use SellingPartnerApi\FeedType;
    3. use SellingPartnerApi\Model\FeedsV20210630 as Feeds;
    4. 。。。。。
    5. //POST_INVENTORY_AVAILABILITY_DATA 原来用POST_PRODUCT_DATA 无效
    6. $feedType = FeedType::POST_INVENTORY_AVAILABILITY_DATA;
    7. $feedsApi = new FeedsApi($config);
    8. // Create feed document
    9. $createFeedDocSpec = new Feeds\CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]);
    10. $feedDocumentInfo = $feedsApi->createFeedDocument($createFeedDocSpec);
    11. $feedDocumentId = $feedDocumentInfo->getFeedDocumentId();
    12. 、。。。。。
    13. $xml = '';
    14. $xml .= '';
    15. $xml .= '
      ';
    16. $xml .= '1.01';
    17. $xml .= '' . $merchant_id . '';
    18. $xml .= '';
    19. $xml .= 'Inventory';
    20. $xml .= '';
    21. $xml .= '1';
    22. //?是否需要 价格更新需要加这个
    23. $xml .= 'Update';
    24. $xml .= '';
    25. // SELLER SKU
    26. $xml .= '' . $seller_sku . '';// 售价
    27. // 发货中心 ,卖家自发货 用 DEFAULT
    28. $xml .= 'DEFAULT';
    29. //choice ,三选一
    30. //$xml .= 'true';
    31. $xml .= '' . $qty . '';
    32. //$xml .= 'FulfillmentNetwork';
    33. //gmdate("Y-m-dTH:i:s.00:00:00Z")
    34. //2022-10-27GMT10:39:16.00:00:000
    35. // $created_after , $created_before两个参数不能同时用
    36. //minOccurs="0"
    37. //$xml .= '' . date('Y-m-d',time()) . '';
    38. //几天内发货 minOccurs="0"
    39. //$xml .= '2';
    40. //切换货运方式 minOccurs="0"
    41. //$xml .= '';
    42. $xml .= '';
    43. $xml .= '';
    44. $xml .= '';
    45. // 同时修改多个时
    46. //$xml .= '';
    47. //$xml .= '2';
    48. // 原来这个多了一行,导致了错误
    49. //$xml .= '';
    50. if ($debug) echo htmlentities($xml);
    51. $feedContents = $xml;
    52. // The Document constructor accepts a custom \GuzzleHttp\Client object as an optional 3rd parameter. If that
    53. // parameter is passed, your custom Guzzle client will be used when uploading the feed document contents to Amazon.
    54. $docToUpload = new \SellingPartnerApi\Document($feedDocumentInfo, $feedType);
    55. $docToUpload->upload($feedContents);
    56. // This is not present in the example
    57. $body = new Feeds\CreateFeedSpecification();
    58. $body->setMarketplaceIds(['ATVPDKIKX0DER']);
    59. $body->setInputFeedDocumentId($feedDocumentId);
    60. $body->setFeedType($feedType['name']);
    61. $result = $feedsApi->createFeed($body);
    62. $feed_id = $result->getFeedId();

  • 相关阅读:
    网址导航收藏引导页面H5源码(自适应引导页HTML源码)-自动检测域名延迟
    css案例14——文字渐变
    icg模块clock gating解析
    μC/OS-II---内核:多任务与调度
    直接root Android设备,会「隐身」的恶意软件AbstractEmu正在偷偷作恶
    流程图高级用法【Markdown进阶篇】
    一文了解HarmonyOSNEXT发布重点内容
    JVM复习总结2024.4.18(很重要)
    什么是子域名?如何设置子域名解析?
    【面试题】面试官问你前端性能优化时,他想问什么?
  • 原文地址:https://blog.csdn.net/zhangfeng1133/article/details/127604917