Retrieve keycloak group id for a specific group - rest

I am trying to access a group id of a specific group from keycloak. What I found is like there is no REST Api call is available for access this one. You can refer here http://www.keycloak.org/docs-api/3.0/rest-api/index.html#_groups_resource. This shows that you can access all group details or specific group details only by using their Id's. Actually what I actually need is I want to access only the id of the specific group. Can anyone let me know how to do this?

You can write it like this:
GET http://localhost:your_port/auth/admin/realms/your_realm_name/groups?search=name_of_the_group
it will return {id, name, path, subGroups} to you..
My Postman Example

The documentation you're using is pretty old. Take a look at the documentation for the latest release:
https://www.keycloak.org/docs-api/4.8/rest-api/#_groups_resource
You can provide a "search" parameter to look for groups by name.
Unfortunately, if you use the name of a subGroup, it returns the entire hierarchy starting from the top-level group, so the API for groups is still problematic.

One way is to enter keycloak admin panel. Then in the Groups option, select a group. Finally you will find the group id in the URL. Like /realms/Applications/groups/bc49dc6c-7c2a-40c4-bf60-fea8c2b1d562

You can get a list of all groups:
GET /admin/realms/{realm}/groups
The response will have group properties including id.
[
{
"id": "8ge163b3-6kc7-40ed-x069-3309eabbcbea",
"name": "group1",
"path": "/group1",
"subGroups": []
}
]

This might come a bit late, but anyway.
There is also the GET /{realm}/group-by-path/{path} endpoint which will return only the group that you desire since path is unique.
Also if someone needs (and since this isn't actually documented, or at least not as of the writing of this answer) if you want to call this endpoint from the admin-cli you can do it as follows:
./kcadm.sh get group-by-path/{path} --realm {realm}
ex.: ./kcadm.sh get group-by-path/parent_group/child_group/grand_child_group --realm realm1

Related

Microsoft Graph query parameter

I use the below query to list all Microsoft 365 groups from our tenant. I would like to add one more filter so that it should only return the groups which have a guest member (Usertype eq 'Guest') in it. Could someone please help
https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified')
Unfortunately there is no such filter to do what you are proposing, you will have to get a list of groups, then use that to query the List members endpoint /groups/{id}/members https://learn.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http . then make your own list.
so to summarize, first run your query, get the guids for each group, then grab the members from each group and do some filtering on the client side for usertype.
In theory group/members filtering is possible as of a few weeks ago, with a query like this: https://graph.microsoft.com/beta/groups/{id}/members?$count=true&$filter=UserType eq 'Guest'
https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/35630488-enable-filter-on-group-members#%7Btoggle_previous_statuses%7D
note that you need to put in a custom request header of consistencylevel as per the docs.

Can't move a subgroup to top group (Keycloak Admin REST API)

I was able to move a group under other groups using POST /{realm}/groups/{id}/children endpoint. However, I can't move the group back to top level.
I can't find any endpoint to do that in the API reference: https://www.keycloak.org/docs-api/6.0/rest-api/index.html#_groups_resource
One weird workaround that came to my mind was deleting and re-creating the group. But then, user relationships will be lost, I'm afraid.
How can I move a group to top?
Use POST /{realm}/groups method with group id in request body to move a group to the root. If you get 500 error pass name attribute as well. Keycloak uses provided group name to verify that no other group with the same name exists in top level.
POST https://keycloak/admin/realms/master/groups
{
"id": "6018073e-1556-4795-9ab9-c22be2615f16",
"name": "Group Name"
}

When to know when I should put the parameters in the body or not?

I was thinking about the most logical request for my api, while trying to think about rest, but I can't wrap my head around which one of these three choices is correct: what would be the best design for the request, supposing that I want to send 10 from some user triggering the request to user2?
1)
POST /pay
body: {"username": "user2", "amount": 10}
2)
POST /pay/users/user2
body: {"amount": 10}
3)
POST /pay/users/user2/10
I don't know how much information should be in the URL vs. how much information should be in the URL.
Suppose you have many users and some functions that users can perform.
So your api could be like:
GET /users # get user list
POST /users + {"name": "John"} # create user
DELETE /users/{userId} # remove user
GET /users/{userId} # get user by id
GET /users/{userId}/payments # get users payments
POST /users/{userId}/payments + {"amount": 10} # submit new payment
GET /users/{userId}/payments/{paymentId} # get users payment details
As you can see it is a very simple resource tree.
I recommend taking a look at restful-api-guidelines
You want to put an Canonical Identifier in the URL and any other data in the body.
For a POST (which is used to create an new resource) the Canonical Identifier generaly does not yet exist therefor it doesn't need one.
The server then creates one and returns it to the client in the location header.
If you mean to update instead of insert, PUT or PATCH should be used. If the username is your Identifier, then option 2 should be used. An identifier should in general not be editable.
Since your "adding" an new payment I would suggest using option 1. But I would call it payment and perhaps add more information about the payment.

Query items user was mentioned in

Is there a way to query work items where a user was mentioned? I am able to receive 'hard-coded' results by querying for
"History"-"Contains word"-"\#Username",
but I want a generic version, which works for all users. (Opposed to writing one query for every user)
Use this predicate:
Field: "ID"
Operator: "In"
Value: "#RecentMentions"
This automatically filters for work items, where current user has been mentioned.
I found it in predefined filter "Mentioned" in "Work Items" section. If you click on "Open in Queries" button, you will get a query with above filter. (This section can even remove the need for that query...)
Note: at present time, works only in VSTS.
https://{org}.visualstudio.com/{project}/_workitems/mentioned/
This would achieve the same result.
There is no way to achieve this by work item query directly just as starain mentioned. You can create a custom hub or custom widget by using VSTS Extension to show these information in web portal.
You can’t achieve that through work item query directly, you could build a app to retrieve data through REST API (https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql), change query text according different conditions (e.g. users)
Your query should be something like this
Select Id,Title From WorkItems Where ID IN (#RecentMentions) order by [System.ChangedDate] desc
here is the reference for rest of the macro's available in ADO rest API.
https://learn.microsoft.com/en-us/azure/devops/boards/queries/query-operators-variables?view=azure-devops

Facebook Marketing API: Is it possible to filter insights by status

I am trying to filter adsets insights by adset status, but when I add a status filter, I get an empty dataset back:
curl "https://graph.facebook.com/v2.7/act_<redacted>/insights?fields=clicks,impressions,cpc,ctr,account_id&time_range%5Bsince%5D=2016-01-12&time_range%5Buntil%5D=2016-09-12&access_token=<redacted>&format=json&filtering=%5B%7B%22field%22:%22status%22,%22operator%22:%22EQUAL%22,%22value%22:%22ACTIVE%22%7D%5D&level=adset"
here is what filtering param looks like before it gets url-encoded:
[{"field":"status","operator":"EQUAL","value":"ACTIVE"}]
I have tried all valid values for status ACTIVE, PAUSED, DELETED, ARCHIVED to no avail.
When I remove filtering param - I see my data.
The question is:
Does anyone know if it is possible to filter by status, and if it is, what I am doing wrong?
It is possible. Using latest version as of March 2018.
You need to actually request all the ads that are ACTIVE and then provide insights as a 'nested' list of fields.
Replace 123456 with your ad account (but leave the 'act_' which is needed)
act_123456/ads?fields=effective_status,name,insights{total_action_value,total_actions,actions},adset_id,campaign_id&filtering=[{'field':'effective_status','operator':'IN','value':['ACTIVE']}]
This also works for /campaigns and /adsets
You can also do this (be sure to include &level=ad):
act_123456/insights?fields=ad_id,adset_id,campaign_name,action_values,campaign_id,total_action_value&level=ad&filtering=[{"field":"campaign.delivery_info","operator":"IN","value":["active"]}]
Filtering by insights isn't possible. At least in v2.7. To get insights for let's say ads I've decided to do the following:
1. Fetch ads that I need via /ads call. This allows me to filter by status.
2. Fetch insights for the same collection of ads and make sure that I ad id is included in the response.
3. Filter the second collection using the first one.
i m using this to filter campaigns with insights , working for me , start playing with it
'filtering'=>
array(
array(
"field"=>"campaign.effective_status",
"operator"=>"IN",
"value"=>$campaigncheckstatus,
),
),
$campaigncheckstatus = array("ACTIVE","PAUSED");
dont forget to json_encode $campaigncheckstatus if passed through url