Question

Adding a user to a user-group via the API

  • 25 April 2022
  • 5 replies
  • 80 views

Hello, 

I am trying to add a guru user to a user group with the API. I am following this verified documentation but cannot figure out the format of the data to post.

I have tried {“emails”: guru_user_email} without success. Are there additional details on this endpoint?

 

Many thanks,

Rodolphe


5 replies

Userlevel 3
Badge

Hi @Rodolphe ! 👋

To add a user to a user group through the API, you can use this endpoint:

POST https://api.getguru.com/api/v1/groups/{group_id}/members

You’ll have to include the user email(s) in the body of the request, formatted like this:

["user@email.com"]

Let me know if this works for you!

Also, the documentation that you linked to brings me back to this post - do you mind resharing that link so we can update our documentation?

Thanks!

Joe

Hi Joe, thank you for your reply ! 

 

The documentation link I was referring to is: https://app.getguru.com/card/c8eMgGai/Add-or-Remove-Users-from-UserGroups-using-the-API

Userlevel 3
Badge

Great - thanks @Rodolphe!

Were you able to successfully get this to work with the endpoint/payload I posted above?

Thanks!

Joe

Yes, the trick was to pass the ["user@email.com"] as a json dump

 

My python code snippet:

import json

def api_add_to_group(group_id, user_email):
headers = {'authorization': API_TOKEN, "Content-Type": "application/json"}
data=[user_email]

response = requests.request("POST", 'https://api.getguru.com/api/v1/groups/'+group_id+'/members', headers=headers, data=json.dumps(data))
return response

 

Userlevel 3
Badge

Awesome - glad to hear you got this working! Let me know if you need anything else.

Joe

Reply