I have this method that makes a PATCH request to this URL:
https://username.visualstudio.com/DefaultCollection/_apis/wit/workitems/8?api-version=1.0
What does this method do: It updates an workItem`s System.Title, that has id 8, In Microsoft Visual Studio - Team Foundation Server
public void testPostVolley(String url) {
/*Post data*/
JSONArray jsonBody = new JSONArray();
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("op","replace");
jsonObject.put("path","/fields/System.Title");
jsonObject.put("value","Welcome to the jungle");
jsonBody.put(jsonObject);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("JSON Array " , String.valueOf(jsonBody));
JsonArrayRequest postRequest = new JsonArrayRequest(Request.Method.PATCH, url,
jsonBody,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d("Response Post Request", response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle Error
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", MainRecyclerListView.TOKEN);
headers.put("Content-Type", "application/json-patch+json");
return headers;
}
};
queue.add(postRequest);
}
}
I tried in POSTMAN with same Headers and same Body and it works, but in the Android app I`m getting this response:
07-06 13:05:49.253 2599-11381/ro.webivo.pockettask E/Volley: [209] BasicNetwork.performRequest: Unexpected response code 400 for https://username.visualstudio.com/DefaultCollection/_apis/wit/workitems/8?api-version=1.0
I Logged also the body I`m sending and is this one:
07-06 13:05:49.017 2599-2599/ro.webivo.pockettask D/JSON Array: [{"op":"replace","path":"/fields/System.Title","value":"Welcome to the jungle"}]
Official API for PATCH request is located here:
https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items
Could you please help me? Is this a Volley problem?
Thank you
ve tried to change Request.Method to POST and add different headers like : headers.put("X-HTTP-Method-Override", "PATCH");, and this time I was getting some json back from VSTS Rest services telling me they accept only Content-Type of application/json-patch+json. I
ve changed it, but I`m getting again answer 400 and nothing else. I tried to log the error.networkresponse.data, but it comes null. Any idea? – dragosiv