atTask c# bulk update return 400 Bad Request Exception

225 Views Asked by At

I have been trying to bulk update data using c# onto workfront,but my code has been returning 400 bad exception. However, when I use the same url on browser it does the update but the code has been returning an exception. Below is my sample code:

        string fullUrl = "";
        if (!path.StartsWith("/"))
        {
            path = "/" + path;
        }


      fullUrl = url + path + ToQueryString(parameters);

      if (DebugUrls) Console.WriteLine("Requesting: {0}", fullUrl);

      WebRequest request = HttpWebRequest.CreateDefault(new Uri(fullUrl));
      Stream responseStream = null;
      try
      {
            //request.Method = "PUT";
            //request.ContentType = "application/x-www-form-urlencoded";
            WebResponse response = request.GetResponse();

             responseStream = response.GetResponseStream();

            return ReadResponse(responseStream);
      } catch (WebException ex) {

            StreamReader sr = new       StreamReader(ex.Response.GetResponseStream(), true);
            Console.WriteLine(sr.ReadToEnd());
      }

        return ReadResponse(responseStream);


    }

At the end of the code, my full url is like below:

https://osvtrial.attask-ondemand.com/attask/api/v4.0/user?method=post&sessionID=ca748236a1d6455ca96c01aad74b65a6&updates=[{\"name\":\"Marc Johansson\",\"title\":\"Director, Information Technology\",\"emailAddr\":\"[email protected]\",\"username\":\"[email protected]\"}]&username=xxxxxx&password=xxxxx

Could someone help on the above issue, Is the issue with the way the url is being passed as the same url when put on the browser works just fine.

1

There are 1 best solutions below

0
On

you need to give proper ID of user object which you want to update. Method should be put not post in case of bulk update. Please refer this link. If you are updating single object then you can use try with below api call

to create bulk projects

PUT /attask/api/v4.0/proj?updates=[{“name”:”Test_Project_1”},{“name”:”Test_Project_2”}]&method=POST&apiKey=123ab-cxxxxxxxxxxxxxxxxxxxxxxxxxx

to update bulk projects

PUT /attask/api/v4.0/proj?method=PUT&updates=[{"ID":"123abcxxxxxxxxxxxxxxxxxxxxxxxxxx","name":"Test_Project_1_ Edit"},{"ID":"123abcxxxxxxxxxxxxxxxxxxxxxxxxxx","name":"Test_Project_2_Edit"}]&apiKey=123abcxxxxxxxxxxxxxxxxxxxxxxxxxx