Using rest api with groups

Posted in

Hi Kento

Hoping you can help me please.

We are looking to add users to groups using the rest API. Is this possible?

Users are being imported / created automatically from another system and we wish them to automatically be assigned to a group which is indicated from a field in the other system.

My dev has said he is looking for the endpoints.

Does my request make sense and if so do you know the solution please?

I found a similar question on the support section of groups in the WordPress repository but I’m not sure your answer there does what I need.

I wondered if renewing my subscription to Groups Import Export would enable this.

Please let me know.

Thanks very much.

Joel

Sorry just to add this is the thread I found on WordPress – https://wordpress.org/support/topic/make-user-groups-available-in-rest/

One Response to Using rest api with groups

  1. George May 25, 2021 at 5:11 pm #

    Hi Joel,

    Welcome to our support forum and many thanks for using our content restriction plugin on your site.

    The topic you found in the community forum has to do with rendering the group which the user belongs to while you’re trying to add a new user to a group after being added to the site.
    Even though Groups plugin doesn’t support REST at the moment, for this specific case you’re describing there is another solution you can use. The WP offers the hook do_action( ‘rest_insert_user’, $user, $request, true ); which is triggered once a user is added via REST API. I think you can use it and for the new user you can add them to the desired group using the Groups API method:

    Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group_id ) );

    Hope it helps.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share