Join and Leave via REST - howto?

Created on 31 January 2023, almost 2 years ago
Updated 2 February 2023, almost 2 years ago

Hi,

is it possible to send a post request to //cms.foo.com/group/[id]/join and //cms.foo.com/group/[id]/leave? I get

{
    "message": "Not acceptable format: json"
}

Do i something wrong?

Thanks
SB

💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany sachbearbeiter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sachbearbeiter
  • 🇨🇦Canada dylan donkersgoed London, Ontario

    In theory I think the way to do this would be by creating a group membership via the API. Unfortunately I think https://www.drupal.org/project/group/issues/2872645 🐛 Creating `Group` content is impossible via REST, JSON:API and GraphQL due to `$context['group']` being required in checking `create` access Needs work would prevent that. Though someone more knowledgeable about the module's internals might wish to jump in and correct me - I am not a maintainer.

    There is an MR attached to that issue. I have never tested it, but it'd probably be worth looking at. I think if you did have the patch you could do something like this with jsonapi to add a group membership:

    curl --location --request POST 'https:/cms.foo.com/jsonapi/group_content/subsite-group_membership' \
    --header 'Accept: application/vnd.api+json' \
    --header 'Content-Type: application/vnd.api+json' \
    --header '<omitted>'  \
    --data-raw '{
        "data": {
            "type": "group_content--subsite-group_membership",
            "attributes": {
                "group_roles": [
                    "subsite-group_administrator"
                ]
            },
            "relationships": {
                "gid": {
                    "data": {
                        "type": "group--subsite",
                        "id": "a6aaabbb-2e59-40c3-b7d2-367e66a4d6a5"
                    }
                },
                "entity_id": {
                    "data": {
                        "type": "user--user",
                        "id": "d19e7446-4b89-4884-9acf-d921e21edc12"
                    }
                }
            }
        }
    }'
    
  • 🇩🇪Germany sachbearbeiter

    Thank you very much! I will have a look ...

Production build 0.71.5 2024