4

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?

1 Answer 1

2

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"]
]
Sign up to request clarification or add additional context in comments.

13 Comments

Not getting the error now but the data is not filtered this is the info i have about the api bitrixsoft.com/rest_help/tasks/task/items/getlist.php
What is the package for JSONObject?
What you need to send is: [ { "ID" : [ "44" ] } ]. Can you construct such query yourself?
org.json.simple.JSONObject
I can try do not know if i will succeed.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.