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


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Support
  3. Some problems with API - PUT user in groups

Some problems with API - PUT user in groups

Scheduled Pinned Locked Moved Solved Support
api
5 Posts 2 Posters 695 Views 2 Watching
  • 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.
  • brainsailerB Offline
    brainsailerB Offline
    brainsailer
    wrote on last edited by girish
    #1

    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?

    girishG 3 Replies Last reply
    0
    • brainsailerB brainsailer

      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?

      girishG Offline
      girishG Offline
      girish
      Staff
      wrote on last edited by
      #2

      @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
      0
      • brainsailerB brainsailer

        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?

        girishG Offline
        girishG Offline
        girish
        Staff
        wrote on last edited by girish
        #3

        @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
        0
        • brainsailerB brainsailer

          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?

          girishG Offline
          girishG Offline
          girish
          Staff
          wrote on last edited by
          #4

          @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
          0
          • brainsailerB Offline
            brainsailerB Offline
            brainsailer
            wrote on last edited by
            #5

            @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
            0
            • girishG girish marked this topic as a question on
            • girishG girish has marked this topic as solved on
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Bookmarks
            • Search