microsoftgraph / microsoftgraph/msgraph-sdk-typescript

Can't add users to groups

Open Beginner friendly
#917 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ToTriage type:bug
Dominant language
TypeScript
Stars
44
Forks
7
Avg merge
12h 40m
Merged PRs (30d)
5

Description

Describe the bug

I'm trying to add a user to a group as follows

export const addUserToGroup = async (userId: string, groupId: string) => {
  try {
    await client()
      .groups.byGroupId(groupId)
      .members.ref.post({
        odataId: `https://graph.microsoft.com/v1.0/directoryObjects/${userId}`,
      });
    return true;
  } catch (error) {
    console.error('Error adding user to group:', error);
    return false;
  }

I get the following error

Error adding user to group: {
  errorEscaped: {
    code: 'Request_BadRequest',
    message: "Unrecognized query argument specified: '@id'.",
    innerError: {
      date: 2025-11-09T12:25:07.000Z,
      requestId: 'xxx',
      clientRequestId: 'xxx'
    }
  },
  message: "Unrecognized query argument specified: '@id'.",
  responseStatusCode: 400,
  responseHeaders: {
    'client-request-id': [ 'xxx' ],
    'content-encoding': [ 'gzip' ],
    'content-type': [ 'application/json' ],
    date: [ 'Sun', ' 09 Nov 2025 23:25:07 GMT' ],
    'request-id': [ 'xxx' ],
    'strict-transport-security': [ 'max-age=31536000' ],
    'transfer-encoding': [ 'chunked' ],
    vary: [ 'Accept-Encoding' ],
    'x-ms-ags-diagnostic': [
      '{"ServerInfo":{"DataCenter":"Australia East"',
      '"Slice":"E"',
      '"Ring":"5"',
      '"ScaleUnit":"000"',
      '"RoleInstance":"xxx"}}'
    ]
  }
}
Expected behavior

The user is added to the group

How to reproduce

Use the code above.
NOTE: This for Azure AD B2C in case it matters

SDK Version

1.0.0-preview.74

Latest version known to work for scenario above?

Has never worked

Known Workarounds

This patch works around it

diff --git a/groups/item/members/ref/index.js b/groups/item/members/ref/index.js
index 9e8a14654fab3754b01311e07c9bd79d2569d5ca..0d396bdf8da2bf273686abbcb08fae6d581682dd 100644
--- a/groups/item/members/ref/index.js
+++ b/groups/item/members/ref/index.js
@@ -8,7 +8,7 @@ import { createODataErrorFromDiscriminatorValue } from '@microsoft/msgraph-sdk/m
 /**
  * Uri template for the request builder.
  */
-export const RefRequestBuilderUriTemplate = "{+baseurl}/groups/{group%2Did}/members/$ref?@id={%40id}{&%24count,%24filter,%24orderby,%24search,%24skip,%24top}";
+export const RefRequestBuilderUriTemplate = "{+baseurl}/groups/{group%2Did}/members/$ref?{&%24count,%24filter,%24orderby,%24search,%24skip,%24top}";
 /**
  * Mapper for query parameters from symbol name to serialization name represented as a constant.
  */
Other information

I'm happy to generate a PR with the above if the fix is sensible.

I'm also new to the API so it's possible my code is not taking the right approach

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with groups/item/members/ref/index.js and inspect RefRequestBuilderUriTemplate, comparing it with the request body and the reported '@id' error. Reproduce the group-member request against the stated SDK scenario and verify that adding the user succeeds without the workaround; check the generated request path before considering the issue done.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.