Group by through rest api

vidyas
Kilo Explorer

Is it possible to achieve group by functionality through   REST API ? I need to fetch user names grouped by group names   .   I have tried

https://xxxxx.service-now.com/api/now/table/sys_user_grmember?sysparm_query=GROUPBYgroup.name&syspar...

And also

https://xx.service-now.com/api/now/table/sys_user_grmember?sysparm_group_by=group&&sysparm_fields=us...

But both does not work ??

Is there a provison to do this ?

2 REPLIES 2

prashantnagaral
Kilo Guru

Hi Vidya,



Try this


api/now/table/sys_user_grmember?sysparm_query=GROUPBYgroup.name&sysparm_fields=group.name,user.user_name



also check web service role mapped to user account which you are trying to access above REST API.



Hit like, Helpful or Correct depending on the impact of the response


Regards


Prashant


Hey thanks prashant that works ! but i am getting the response as follows   :


{


"result": {



"group.name": "CAB Approval"


"user.user_name": "ron.kettering"


},{



"group.name": "CAB Approval"


"user.user_name": "howard.johnson"


}] }



  Is it possible to transform it into



{


"result":


{


"CAB Approval" :


[{"user.user_name": "ron.kettering"},{"user.user_name": "howard.johnson"}]


}


] }