I am trying to post some data a custom API using volley. This is the model of the API which I am trying to update information too. It can be found on http://ecoproduce.eu/swagger/index.html under the following POST link: http://ecoproduce.eu/api/User/register/
{
"firstName": "string",
"lastName": "string",
"email": "string",
"password": "string",
"zipCode": 0,
"state": 0,
"account": 0
}
When I try to add a new test user to the API I receive the following error:
E/Volley: [9583] BasicNetwork.performRequest: Unexpected response code 400 for http://ecoproduce.eu/api/User/register/
E/Error response: com.android.volley.ClientError
This is the function I use to POST the user.
private void addUser() {
RequestQueue requestQueue = Volley.newRequestQueue(this);
JsonArrayRequest arrayRequest = new JsonArrayRequest(
Request.Method.POST,
"http://ecoproduce.eu/api/User/register/",
null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error response", error.toString());
}
})
{
@Override
protected Map<String,String> getParams() {
Map<String,String> params = new HashMap<String,String>();
params.put("firstName", "Vasko");
params.put("lastName", "Vasilev");
params.put("email", "vasko@hotmail.com");
params.put("password", "18yoBonev");
params.put("zipCode", "0");
params.put("state", "1");
params.put("account", "2");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
requestQueue.add(arrayRequest);
}
I have tried looking up solutions to this but I have not been able to find anything helpful. Could the error be occurring because I am trying to pass the zipCode, state and account as Strings even tho they are integers in the model? If so, how can I pass them as integers? Currently I am overriding the getParams() function which must return a Map instance. I would like to apologise in advance if this questions has a simple solution, it is my first time working with RESTful API.