API
Version 7.x > API > REST API Update SKU PUT View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Joe - 11/30/2013 10:29:22 AM
   
REST API Update SKU PUT
Hi,

I am trying to update a SKU_Info's SKUAvailableItems field. I receive a 404 error. Am I sending the PUT request to the wrong URL? Here is my request:

PUT http://www.mysite.com/rest/ecommerce.sku/2 HTTP/1.1
Authorization: Basic xyz
Content-Type: text\xml
Host: www.mysite.com
Content-Length: 74
Expect: 100-continue

<data><COM_SKU><SKUAvailableItems>100</SKUAvailableItems></COM_SKU></data>

Response

HTTP/1.1 404 Not Found
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Sat, 30 Nov 2013 16:17:57 GMT
Connection: close
Content-Length: 4881

mysite.com/rest/ecommerce.sku/2 exists. When I visit it, I receive this XML:

<data>
<COM_SKU>
<SKUID>2</SKUID>
<SKUNumber>12345</SKUNumber>
<SKUName>Hard Cover</SKUName>
<SKUDescription>This is a hardcover book.</SKUDescription>
<SKUPrice>10</SKUPrice>
<SKUEnabled>true</SKUEnabled>
<SKUGUID>f1f5826b-f9db-44b4-9224-33f8a8515123</SKUGUID>
<SKUImagePath>
~/getmetafile/85900275-25e3-4125-b33e-0a8536bf7893/200px-Steve_Jobs_by_Walter_Isaacson.aspx
</SKUImagePath>
<SKUSellOnlyAvailable>false</SKUSellOnlyAvailable>
<SKUCustomData/>
<SKUOptionCategoryID>1</SKUOptionCategoryID>
<SKULastModified>2012-05-19T08:07:35.243-07:00</SKULastModified>
<SKUCreated>2012-05-19T08:07:35.117-07:00</SKUCreated>
<SKUSiteID>1</SKUSiteID>
<SKUNeedsShipping>true</SKUNeedsShipping>
<SKUProductType>PRODUCT</SKUProductType>
</COM_SKU>
</data>

User avatar
Member
Member
kentico_sandroj - 12/1/2013 3:07:01 PM
   
RE:REST API Update SKU PUT
Hello,

Are you able to GET and POST? If so, this article may explain why the PUT (and DELETE) would not work. Please let me know if that is the case here.

Best Regards,
Sandro

User avatar
Certified Developer v7
Certified  Developer v7
Joe - 12/1/2013 3:35:39 PM
   
RE:REST API Update SKU PUT
Hi,

I am able to perform GET requests, but not POST or PUT requests. I have removed the WebDAV module from the article, however, the issue persists. I also added the verbs to the extensionless urls module in IIS 7.

User avatar
Member
Member
kentico_sandroj - 12/1/2013 4:06:34 PM
   
RE:REST API Update SKU PUT
Hello,

Thank you for confirming that. In that case the issue is likely in the path, have you tried: /rest/ecommerce.sku/currentsite

Also, please review the documentation and ensure the objects are not read-only.

Regards,
Sandro

User avatar
Certified Developer v7
Certified  Developer v7
Joe - 12/1/2013 6:06:26 PM
   
RE:REST API Update SKU PUT
Thanks for the info. I did get it to work with POST. I adjusted my web.config and I got it to work:

web.config changes

public bool UpdateStock(string sku, int quantity)
{
COM_SKU theSKU = GetSKUByNumber(sku);
theSKU.SKUAvailableItems = quantity;
string url = m_BaseUrl + String.Format("/rest/ecommerce.sku/{0}", theSKU.SKUID);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

string userP = m_UserName + ":" + m_Password;
byte[] authBytes = Encoding.UTF8.GetBytes(userP).ToArray();
req.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes));


req.Timeout = 30000;
req.Method = "PUT";
req.ContentType = @"text\xml";

string postString = string.Empty;
using (var writer = new StringWriter())
{
new XmlSerializer(theSKU.GetType()).Serialize(writer, theSKU);
postString = writer.GetStringBuilder().ToString();
}


req.ContentLength = Encoding.UTF8.GetByteCount(postString);
using (Stream sw = req.GetRequestStream())
{
byte[] bytes = Encoding.UTF8.GetBytes(postString);
sw.Write(bytes, 0, bytes.Length);
}

HttpWebResponse resp = null;

try
{
resp = (HttpWebResponse)req.GetResponse();


if (resp.StatusCode == HttpStatusCode.Created)
{
return true;
}

}
catch (Exception)
{

}

return false;
}

User avatar
Member
Member
kentico_sandroj - 12/1/2013 6:10:29 PM
   
RE:REST API Update SKU PUT
Great, I am glad you got it to work. Thank you for sharing the solution!

Best Regards,
Sandro