ockert nel
ockert nel

Reputation: 41

Sending Parameters to Rest Api with httpost in java as an array

I am connecting to a rest api when I do the post without parameters I get a return but as soon as I try to add parameters

JSONObject obj = new JSONObject();
    obj.put("ID", "44");
    StringEntity se = new StringEntity(obj.toString());
    post.setEntity(se);
    post.setHeader("Accept", "application/json");
    post.setHeader("Content-type", "application/json");
    HttpResponse response = client.execute(post);

to filter the data i get the following reply

{"error":"ERROR_CORE","error_description":"TASKS_ERROR_EXCEPTION_#256; Param #0 (arOrder) for method ctaskitem::getlist() expected to be of type \u0022array\u0022, but given something else.; 256/TE/WRONG_ARGUMENTS\u003Cbr\u003E"}

How do I send the parameters as an array?

Upvotes: 4

Views: 619

Answers (1)

Opal
Opal

Reputation: 84756

Please try:

List<String> orders = new ArrayList<>();
orders.add("44");
JSONObject obj = new JSONObject();
obj.put("arOrder", orders);
StringEntity se = new StringEntity(obj.toString());
post.setEntity(se);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(post);

After reading the docs, please try to send the following JSON:

[
  { "ID" : "desc" }, 
  { "ID" : ["44"] }, // or [44] plain int
  [ "ID", "TITLE"]
]

Upvotes: 2

Related Questions