记录点滴

记录生活

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  67 随笔 :: 2 文章 :: 233 评论 :: 17万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

HI all,

During past few days i was given a project to develop an application using amazon and ebay api in C#,.net 4.

Well i had a very very bad experience with amazon the documentation was just terrible , no example code. Some samples but not all the parts , so very hard to know anything from their site.

So i searched a lot for almost three days , and developed the update amazon orders status with of multiple messages.

i am attaching/pasting complete code for anyone like me who will i am sure have trouble finding examples, you can use this as it is just change the authorization keys and it will work :) .

——————–Amazon update order status api——————————————-

First of all get the classes downloaded into your application from https://developer.amazonservices.com/gp/mws/api.html?ie=UTF8&section=feeds&group=bde&version=latest

Basically you need to use the submitfeedfunction to post info to amazon , so my first problem was i was searching in orders api .

The main thing using amazon api is to match the exact xml or flat file pattern to post info otherwise it wont work ,even slightest detail like different time format wont work.

What i do is that i have list of orders many with checkboxes i select multiple and call this function on button click , all the check boxes values are combined with , example:

123-4242453252,234-32434-234234 etc..

public void updateAmazonOrderStatus(string orderidz)

{

string curDate = string.Empty;

curDate = GetFormattedTimestamp(DateTime.Now);

/// You need to follow this datetime format that is what i have learned.Maybe i am wrong but i always worked when i used this format and never on any other.

//   ——————————————————————-

String accessKeyId = “#”;

String secretAccessKey = “#”;

String merchantId = “#”;

String marketplaceId = “#”;

string postingOrderFile = string.Empty;

string dateTest = string.Empty;

dateTest = curDate;

postingOrderFile = GenerateInventoryDocument(orderidz, merchantId, dateTest);

UTF8Encoding encoding = new UTF8Encoding();

byte[] byteData = encoding.GetBytes(postingOrderFile);

Stream s = new MemoryStream(byteData);

const string applicationName = “C#”;

const string applicationVersion = “4″;

MarketplaceWebServiceConfig config = new MarketplaceWebServiceConfig();

config.ServiceURL = “https://mws.amazonservices.co.uk&#8221;;

//Change the service url according to your need, .co.uk,de,com,ca etc…

MarketplaceWebService.MarketplaceWebService service = new MarketplaceWebServiceClient(accessKeyId, secretAccessKey, applicationName, applicationVersion, config); // You will get these classes from the link i pasted above

MarketplaceWebService.Model.SubmitFeedRequest request = new MarketplaceWebService.Model.SubmitFeedRequest();// You will get these classes from the link i pasted above

request.Merchant = merchantId;

request.MarketplaceIdList = new MarketplaceWebService.Model.IdList();

request.MarketplaceIdList.Id = new List<string>(new string[] { marketplaceId });

request.FeedContent = s;

request.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(request.FeedContent);

request.FeedContent.Position = 0;

request.PurgeAndReplace = true;

request.FeedType = “_POST_ORDER_FULFILLMENT_DATA_”;

SubmitFeedSample.InvokeSubmitFeed(service, request);

}

//———————————————————————————————————————————————-

//Now posting the various sub-function used in the code above:

public String GetFormattedTimestamp(DateTime dt)

{

DateTime utcTime;

if (dt.Kind == DateTimeKind.Local)

{

utcTime = new DateTime(

dt.Year,

dt.Month,

dt.Day,

dt.Hour,

dt.Minute,

dt.Second,

dt.Millisecond,

DateTimeKind.Local).ToUniversalTime();

}

else

{

// If DateTimeKind.Unspecified, assume UTC.

utcTime = dt;

}

return utcTime.ToString(“yyyy-MM-dd\\THH:mm:ss.fff\\Z”, CultureInfo.InvariantCulture);

}

//I needed this function to generate the xml document needed to post to amazon so it knows which order status to update.

public string GenerateInventoryDocument(string orderNumber, string merchantID,string datecurrent)

{

string myString = string.Empty;

myString = myString + “<?xml version=\”1.0\” ?>”;

myString =myString+ “<AmazonEnvelope xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” xsi:noNamespaceSchemaLocation=\”amzn-envelope.xsd\”>”;

myString = myString + “<Header>”;

myString = myString + “<DocumentVersion>1.01</DocumentVersion>”;

myString = myString + “<MerchantIdentifier>” + merchantID + “</MerchantIdentifier>”;

myString = myString + “</Header>”;

myString = myString + “<MessageType>OrderFulfillment</MessageType>”;

//Add the individual messages to the document.

//As i had multiple order ids so splitting them and adding them to the xml one by one.

string[] splitter = null;

splitter = orderNumber.Split(‘,’);

if (splitter.Length > 0)

{

for (int i = 1; i <= splitter.Length; i++)

{

if (splitter[i-1] != “”)

{

this.CreateInventoryMessage(splitter[i - 1], i, ref myString, datecurrent);

}

}

}

myString = myString + “</AmazonEnvelope>”;

return myString;

}

private void CreateInventoryMessage(string orderID, int MessageID, ref string myString, string curdate)

{

myString = myString + “<Message>”;

myString = myString + “<MessageID>” + MessageID.ToString() + “</MessageID>”;

myString = myString + “<OperationType>Update</OperationType>”;

myString = myString + “<OrderFulfillment>”;

myString = myString + “<AmazonOrderID>” + orderID + “</AmazonOrderID>”;

myString = myString + “<FulfillmentDate>” + curdate + “</FulfillmentDate>”;

myString = myString + “</OrderFulfillment>”;

myString = myString + “</Message>”;

}

And the code ends here :) , it will work 100 % im sure and you do not need to search so much stuff to find all this and put together , that is what i have been through hope you find it usefull anything else just let me know,

Thank you for reading.

MR..XXXXXXXX

posted on   啊峰  阅读(1373)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示