mgodinho Posted April 20, 2020 Share Posted April 20, 2020 Hi everyone, I'm trying to create a new category and/or update a product with c# and there is an error everytime. Anyone can give me a "hand" to understand where the problem is? :) private string WebService_URL = "http://mysite.com/prestashop/api"; private string WebService_LoginName = PrestashopAPIKey; public string conps(string TableName, String Method) { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(WebService_URL + "/" + TableName); request.Credentials = new NetworkCredential(WebService_LoginName, ""); byte[] bytes; bytes = System.Text.Encoding.ASCII.GetBytes(myXML); request.ContentType = "text/xml; encoding='utf-8'"; request.ContentLength = bytes.Length; request.Method = Method; System.IO.Stream requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); HttpWebResponse response; response = (HttpWebResponse)request.GetResponse(); return response.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); return ""; } } private class CRUDMethod { public static string Create = "POST"; public static string Read = "GET"; public static string Update = "PUT"; public static string Delete = "DELETE"; } string oi = conps("categories", CRUDMethod.Create); string oi = conps("products", CRUDMethod.Update); this is myXML to update product: <prestashop xmlns:xlink='http://www.w3.org/1999/xlink'><product><id>1</id><active>0</active></product></prestashop> this is my myXML to create category:<prestashop> <category> <id>100</id> <id_parent>0</id_parent> <active>1</active> <id_shop_default>1</id_shop_default> <is_root_category>0</is_root_category> <position>0</position> <date_add>2020-04-20 16:11:00</date_add> <date_upd>2020-04-20 16:11:00</date_upd> <name> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </name> <link_rewrite> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </link_rewrite> <description> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </description> <meta_title> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </meta_title> <meta_description> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </meta_description> <meta_keywords> <language id="2" xlink:href="http://myite.com/prestashop/api/languages/2">test</language> </meta_keywords> <associations> <categories nodeType="category" api="categories"> </categories> <products nodeType="product" api="products"/> </associations> </category> </prestashop> Thank you in advance, Mario Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now