Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


    Cloudron Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular

    Solved Some problems with API - PUT user in groups

    Support
    api
    2
    5
    50
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • brainsailer
      brainsailer last edited by girish

      Why 2 different ways for the same thing?

      1. https://my.example.com/api/v1/groups/{groupId}/members
        2.https://my.example.com/api/v1/users/{userId}/groups

      ..but both are not working. I tried all: normal arrays, nested arrays, array with 2 members. Error messages:

      1. "missing or invalid userIds fields"
      2. "API call requires a groups array."

      Example:
      {
      "groupIds": [
      "gidXXXXXXXXX"
      ]
      }

      Maybe the API documentation is wrong?

      girish 3 Replies Last reply Reply Quote 0
      • girish
        girish Staff @brainsailer last edited by

        @brainsailer Try something like this:

        curl 'https://my.example.com/api/v1/groups/{groupId}/members' -X PUT -H 'Authorization: Bearer xx' -H 'Content-Type: application/json' -d '{"userIds":["uid-19953f08-c020-46a1-84ef-75e0274e6c1e"]}'
        

        Alternately:

        curl 'https://my.smartserver.io/api/v1/users/{userId}/groups' -X PUT -H 'Authorization: Bearer xxxx' -H 'Content-Type: application/json' -d '{"groupIds":["gid-3e96c503-d30f-4db8-aa37-ecaf98fa33fa"]}'
        
        1 Reply Last reply Reply Quote 0
        • girish
          girish Staff @brainsailer last edited by girish

          @brainsailer said in Some problems with API - PUT user in groups:

          Why 2 different ways for the same thing?

          Initially, there was only a way to assign members to groups. So, we had the simple /api/v1/groups/{groupId}/members. Later, people wanted to add a specific user to one or more groups i.e via the groups dropdown in the user edit dialog. Accomplishing this with the /api/v1/groups/{groupId}/members route is complicated. We have to go into each group, get members of each group and set the members of each group. One has to also do this for the groups in which the user is removed.

          So, to simplify the frontend (and also for correctness since this has to be done in a single transaction), we added a new route /api/v1/users/{userId}/groups.

          1 Reply Last reply Reply Quote 0
          • girish
            girish Staff @brainsailer last edited by

            @brainsailer said in Some problems with API - PUT user in groups:

            "missing or invalid userIds fields"
            "API call requires a groups array."

            BTW, these both seems like you are not setting the content-type as json when sending the request.

            1 Reply Last reply Reply Quote 0
            • brainsailer
              brainsailer last edited by

              @girish said in Some problems with API - PUT user in groups:

              {"groupIds":["gid-3e96c503-d30f-4db8-aa37-ecaf98fa33fa"]}

              Thank you, works fine. It was a spelling-error in the "content-type" .

              1 Reply Last reply Reply Quote 0
              • Topic has been marked as a question  girish girish 
              • Topic has been marked as solved  girish girish 
              • First post
                Last post
              Powered by NodeBB