Skip to main content
Question

Adding a user to a user-group via the API

  • April 25, 2022
  • 5 replies
  • 96 views

Rodolphe

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

Joe Duffy
Guru Employee
Forum|alt.badge.img
  • Guru Employee
  • 72 replies
  • April 25, 2022

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


Rodolphe
  • Author
  • Knewbie
  • 2 replies
  • April 27, 2022

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


Joe Duffy
Guru Employee
Forum|alt.badge.img
  • Guru Employee
  • 72 replies
  • April 27, 2022

Great - thanks @Rodolphe!

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

Thanks!

Joe


Rodolphe
  • Author
  • Knewbie
  • 2 replies
  • April 27, 2022

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

 


Joe Duffy
Guru Employee
Forum|alt.badge.img
  • Guru Employee
  • 72 replies
  • April 27, 2022

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

Joe