title: PostAsJson JsonArray C# Web API
body: <p>I am trying to post an array called categories using the BigCommerce API. I receive a response that my array [1] is an invalid Json array.</p>
  
  <p>To test, go to <a href="https://developer.bigcommerce.com/console" rel="nofollow">https://developer.bigcommerce.com/console</a> Products > create a new product.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    public bool CreateNewProduct(string name, string sku, decimal price, decimal weight, List&lt;string&gt; categories = null, string type = "physical", string availability = "available")
      {
          HttpClientHandler handler = new HttpClientHandler();
          handler.Credentials = new NetworkCredential(username, api_key);
          handler.UseDefaultCredentials = true;
          HttpClient client = new HttpClient(handler)
          {
              BaseAddress = new Uri(baseUrl),
          };
  
  
          Dictionary&lt;string, string&gt; values = new Dictionary&lt;string, string&gt;();
          values.Add("name", name);
          values.Add("price", price.ToString());
          values.Add("weight", weight.ToString());
          values.Add("sku", sku);
  
          string cats = string.Empty;
  
          if (categories == null)
          {
              categories = new List&lt;string&gt;();
              categories.Add(GetAllCategories().FirstOrDefault().ID.ToString());
          }
          else
          {
              foreach (string theInt in categories)
              {
                  cats += theInt + ",";
              }
  
              cats.Remove(cats.Length - 1);
  
          }
  
          values.Add("categories", "[1]");
          values.Add("type", type);
          values.Add("availability", availability);
  
          string userP = username + ":" + api_key;
          byte[] authBytes = Encoding.UTF8.GetBytes(userP).ToArray();
          client.DefaultRequestHeaders.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes));
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          string url = "products.json";
  
          HttpResponseMessage response = client.PostAsJsonAsync(url, values).Result;
          if (response.IsSuccessStatusCode)
          {
              Product result = response.Content.ReadAsAsync&lt;Product&gt;().Result;
              if (result != null)
              {
                  return true;
              }
          }
  
          return false;
  
      }
  </code></pre>
  
  <p>Here is my request:</p>
  
  <pre><code>POST xyz/api/v2/products.json HTTP/1.1
  Authorization: Basic adf
  Accept: application/json
  Content-Type: application/json; charset=utf-8
  Host: x
  Content-Length: 132
  Expect: 100-continue
  
  {"name":"test product 1","price":"100","weight":"1","sku":"test111","categories":"[1]","type":"physical","availability":"available"}
  </code></pre>
  
  <p>Here is the response:</p>
  
  <pre><code>[{"status":400,"message":"The field 'categories' is invalid.","details":{"invalid_reason":"The provided value is not a valid array."}}]
  </code></pre>