Hi
I'm writing some code for a customer using the REST api, and I've a problem with the members api when getting the members of an empty group.
When the group contains no users, the response json "results" is just an empty json object, but the api docs say it should be an array.
This is causing the json deserialization to fail, as the target class is List<Result> Results, but there is no array to deserialize. I think I'll need to flatten it in all cases, but my expectation would just have been an empty array, not an object.
What is the origin of your inquiry?
To recreate in CS with Postman:
1. create a new group is CS, do not add any users, note the group id
2. use POST: /api/v1/auth with username and password to get token
3. add token to OTCSTicket header in GET: /api/v2/members/<group_id>/members
Results is:
{
"collection": {
"paging": {
"limit": 1000,
"page": 1,
"page_total": -1,
"range_max": 0,
"range_min": 1,
"total_count": 0
},
"sorting": {
"sort": [
{
"key": "sort",
"value": "asc_name"
}
]
}
},
"links": {
"data": {
"self": {
"body": "",
"content_type": "",
"href": "/api/v2/members/79088/members?fields=results&limit=1000",
"method": "GET",
"name": ""
}
}
},
"results": {}
}
Note the "results": {}
the api docs say:
{
"collection": [
{}
],
"results": [
{
"data": []
}
],
"links": [
{}
]
}
(results in an array ([]) not an object ({}).
4. change the id in the GET request to a group id with some members.
this time the response for results is:
"results": [
{
"data": {
"properties": {
"birth_date": null,
"business_email": null,
"business_fax": null,
"business_phone": null,
"cell_phone": null,
"deleted": false,
an array!
this therefore looks like a bug to me as there's inconsistent behavior.
Because of this, the object is defined as
public class MyObject {
public List<result> results {get;set;}
}
but JSON won't deserilize it if there's no group members as it doesn't return an array.
Any ideas on how to work around this?
PS: does ?fields=<field> query parameter do anything in v2 api? I can't get it to make any difference!
regards
Guy.