I am trying to upload items with Walmart marketplace APIs(Bulk Create Item) but always get a response as 500 Internal server error. Any Ideas? the other Api functions are okay but not this func.. Actually Others are using Method is "application/xml" but this is using "multipart/form-data;"
Note that the XML strings/example in the code below are taken from https://developer.walmartapis.com/#the-item-object
and then I changed IDs property.
public bool RequestUpdateItem()
{
string strBaseUrl = string.Format("https://marketplace.walmartapis.com/v2/feeds?feedType=item");
string strRequestMethod = "POST";
WalmartSignature Signature = new WalmartSignature(consumerId, privateEncodedStr, strBaseUrl, strRequestMethod);
string strSignature = string.Empty;
HttpWebRequest httpWebRequest = null;
HttpWebResponse httpWebResponse = null;
WalmartOrderModel orderModel = new WalmartOrderModel();
StringBuilder strBuilder = new StringBuilder();
bool bReturnValue = false;
try
{
strSignature = Signature.GetSignature(null); // null -> generate timestamp
httpWebRequest = (HttpWebRequest)WebRequest.Create(strBaseUrl);
httpWebRequest.Method = strRequestMethod;
httpWebRequest.Accept = "application/xml";
httpWebRequest.ContentType = "multipart/form-data;";
httpWebRequest.Headers.Add("WM_SVC.NAME", "Walmart Marketplace");
httpWebRequest.Headers.Add("WM_SEC.AUTH_SIGNATURE", strSignature);
httpWebRequest.Headers.Add("WM_CONSUMER.ID", Signature.ConsumerId);
httpWebRequest.Headers.Add("WM_SEC.TIMESTAMP", Signature.TimeStamp);
httpWebRequest.Headers.Add("WM_QOS.CORRELATION_ID", Guid.NewGuid().ToString());
string strRequestBody =
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<MPItemFeed xmlns=""http://walmart.com/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""http://walmart.com/MPItem.xsd"">
<MPItemFeedHeader>
<version>2.1</version>
<requestId>333pecEl55nics</requestId>
<requestBatchId>333ecElect55cs38</requestBatchId>
</MPItemFeedHeader>
<MPItem>
<sku>BDK72wsd44f</sku>
<Product>
<productName>QVS</productName>
<longDescription>QVS</longDescription>
<shelfDescription>QVS</shelfDescription>
<shortDescription>QVS</shortDescription>
<mainImage>
<mainImageUrl>http://images.antonline.com/img-main/500/037229400328.jpg</mainImageUrl>
</mainImage>
<productIdentifiers>
<productIdentifier>
<productIdType>UPC</productIdType>
<productId>220740171234</productId>
</productIdentifier>
</productIdentifiers>
<productTaxCode>2038710</productTaxCode>
<additionalProductAttributes>
<additionalProductAttribute>
<productAttributeName>product_id_override</productAttributeName>
<productAttributeValue>true</productAttributeValue>
</additionalProductAttribute>
</additionalProductAttributes>
<Electronics>
<brand>QVS</brand>
<ElectronicsCables>
</ElectronicsCables>
</Electronics>
</Product>
<price>
<currency>USD</currency>
<amount>99.29</amount>
</price>
<shippingWeight>
<value>0.12</value>
<unit>LB</unit>
</shippingWeight>
</MPItem>
</MPItemFeed>";
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(strRequestBody);
writer.Flush();
stream.Position = 0;
httpWebRequest.ContentLength = stream.Length;
using (Stream requestStream = httpWebRequest.GetRequestStream())
{
stream.CopyTo(requestStream);
//requestStream.Write(stream, 0, stream.Length);
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
if (httpWebResponse.StatusCode == HttpStatusCode.OK)
{
Stream streamResponse = httpWebResponse.GetResponseStream();
var responseResult = XDocument.Load(streamResponse);
}
}
}
catch (Exception ex)
{
Console.WriteLine("RequestUpdateItem(): " + ex);
}
return bReturnValue;
}