title: Add New Category in PrestaShop via Web Services use c#
body: <p>I am trying to add new category in prestashop 1.5 via web services using <code>c#</code>. I made this successfuly with <code>PHP</code> but I couldn't make with <code>C#</code> </p>
  
  <p>My Code in <code>PHP</code> is below and works fine. </p>
  
  <pre><code>function PS_new_category($n_is_root_category, $n_id_parent, $n_id_parent, $n_active, $n_l_id,$n_l_id_sec, $n_name, $n_desc, $n_link_rewrite, $n_meta_title, $n_meta_description, $n_meta_keywords) {
  
  global $webService;
  
  $xml = $webService -&gt; get(array('url' =&gt; PS_SHOP_PATH . '/api/categories?schema=blank'));
  $resources = $xml -&gt; children() -&gt; children();
  unset($resources -&gt; id);
  unset($resources -&gt; position);
  unset($resources -&gt; id_shop_default);
  unset($resources -&gt; date_add);
  unset($resources -&gt; date_upd);
  $resources -&gt; active = $n_active;
  $resources -&gt; id_parent = $n_id_parent;
  $resources -&gt; id_parent['xlink:href'] = PS_SHOP_PATH . '/api/categories/' . $n_id_parent;
  $resources -&gt; is_root_category = $n_is_root_category;
  $node = dom_import_simplexml($resources -&gt; name -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_name));
  $resources -&gt; name -&gt; language[0][0] = $n_name;
  $resources -&gt; name -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; name -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  //
  $resources -&gt; name -&gt; language[1][1] = $n_name;
  $resources -&gt; name -&gt; language[1][1]['id'] = 2;//$n_l_id;
  $resources -&gt; name -&gt; language[1][1]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . 2;//$n_l_id;
  
  $node = dom_import_simplexml($resources -&gt; description -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_desc));
  $resources -&gt; description -&gt; language[0][0] = $n_desc;
  $resources -&gt; description -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; description -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  $node = dom_import_simplexml($resources -&gt; link_rewrite -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_link_rewrite));
  $resources -&gt; link_rewrite -&gt; language[0][0] = $n_link_rewrite;
  $resources -&gt; link_rewrite -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; link_rewrite -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  
  //
  $resources -&gt; link_rewrite -&gt; language[1][1] = $n_link_rewrite;
  $resources -&gt; link_rewrite -&gt; language[1][1]['id'] = 2;//$n_l_id;
  $resources -&gt; link_rewrite -&gt; language[1][1]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . 2;//$n_l_id;
  
  $node = dom_import_simplexml($resources -&gt; meta_title -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_meta_title));
  $resources -&gt; meta_title -&gt; language[0][0] = $n_meta_title;
  $resources -&gt; meta_title -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; meta_title -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  //
  $resources -&gt; meta_title -&gt; language[1][1] = $n_meta_title;
  $resources -&gt; meta_title -&gt; language[1][1]['id'] = $n_l_id_sec;
  $resources -&gt; meta_title -&gt; language[1][1]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id_sec;
  
  $node = dom_import_simplexml($resources -&gt; meta_description -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_meta_description));
  $resources -&gt; meta_description -&gt; language[0][0] = $n_meta_description;
  $resources -&gt; meta_description -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; meta_description -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  $node = dom_import_simplexml($resources -&gt; meta_keywords -&gt; language[0][0]);
  $no = $node -&gt; ownerDocument;
  $node -&gt; appendChild($no -&gt; createCDATASection($n_meta_keywords));
  $resources -&gt; meta_keywords -&gt; language[0][0] = $n_meta_keywords;
  $resources -&gt; meta_keywords -&gt; language[0][0]['id'] = $n_l_id;
  $resources -&gt; meta_keywords -&gt; language[0][0]['xlink:href'] = PS_SHOP_PATH . '/api/languages/' . $n_l_id;
  try {
      $opt = array('resource' =&gt; 'categories');
      $opt['postXml'] = $xml -&gt; asXML();
      $xml = $webService -&gt; add($opt);
  } 
  catch (PrestaShopWebserviceException $ex) {
      czarodziej_log("PS/SYNCHRONIZACJA KATEGORII: " . $e-&gt;getMessage(), 1);
      // my log function
      echo "&lt;br&gt;LOG: ".$e-&gt;getMessage();
  }
  }
  </code></pre>
  
  <p>And my code, witch doesn't work, in <code>c#</code> is this</p>
  
  <pre><code>private string AddCategoryToEShop(string categoryName) 
          {
              XtraMessageBox.Show("Create New Category");
              //PrestaShop.WebService.PrestaShopApi api = PrestashopHelper.CreateNewApiObject();
              string url = _eshopUrl;
              HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url + "/api/categories?schema=blank");
              request.KeepAlive   = true;
              request.Credentials = new NetworkCredential(_webServiceUserKey, _webServiceUserPassword);
  
              request.Method = "POST";
  
              string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x", CultureInfo.InvariantCulture);
  
              byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
  
              request.ContentType = "multipart/form-data; boundary=" + boundary;
  
              string postData = @"&lt;category&gt;
  
                                          &lt;id_parent xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/categories/0'&gt;2&lt;/id_parent&gt;
                                          &lt;active&gt;1&lt;/active&gt;
                                          &lt;is_root_category&gt;1&lt;/is_root_category&gt;
                                          &lt;name&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;New category name C Sharp&lt;/language&gt;&lt;language id='2' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/2'&gt;Νέα κατηγορία από C Sharp&lt;/language&gt;&lt;/name&gt;
                                          &lt;link_rewrite&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;-dfs-&lt;/language&gt;&lt;language id='2' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/2'&gt;-dfs-&lt;/language&gt;&lt;/link_rewrite&gt;
                                          &lt;description&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;New desc ...&lt;/language&gt;&lt;language id='2'/&gt;&lt;/description&gt;
                                          &lt;meta_title&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;meta-title&lt;/language&gt;&lt;language id='2' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/2'&gt;meta-title&lt;/language&gt;&lt;/meta_title&gt;
                                          &lt;meta_description&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;meta desc&lt;/language&gt;&lt;language id='2'/&gt;&lt;/meta_description&gt;
                                          &lt;meta_keywords&gt;&lt;language id='1' xlink:href='http://localhost/dev/clients/Anthagora/Prestashop/trunk/src/api/languages/1'&gt;some,one,keywords&lt;/language&gt;&lt;language id='2'/&gt;&lt;/meta_keywords&gt;
                                      &lt;/category&gt;";
  
  
  
  
              byte[] postDataBytes = System.Text.Encoding.ASCII.GetBytes(postData);
              //create recuest content
              request.ContentLength = postDataBytes.Length;// +boundarybytes.Length;
              request.GetRequestStream().Write(postDataBytes, 0, postDataBytes.Length);
              // request.GetRequestStream().Write(content, 0, content.Length);
              //request.GetRequestStream().Write(boundarybytes, 0, boundarybytes.Length);
  
              string responsText = string.Empty;
              try {
                  WebResponse response = request.GetResponse();
                  response.Close();
  
                  responsText = string.Format("Image of Product {0} added successfully to e-shop", _productId.ToString());
              }
              catch (Exception ex) {
                  responsText = ex.ToString();
                  XtraMessageBox.Show("Exception: (AddCategoryToEShop) " + ex.Message);
              }
              finally {
  
              }
  
              uploadProgresslistBox.Invoke((MethodInvoker)(() =&gt; uploadProgresslistBox.Items.Add(responsText)));
  
              return responsText;
  
          }
  </code></pre>
  
  <p>Can anyone help me??</p>