Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update sponsors of user #1002

Open
Doc94 opened this issue Jul 9, 2024 · 2 comments
Open

Cannot update sponsors of user #1002

Doc94 opened this issue Jul 9, 2024 · 2 comments

Comments

@Doc94
Copy link

Doc94 commented Jul 9, 2024

Describe the bug

Im updating a user with new sponsors but in the update user throw an internal issue.

Expected behavior

Update the user with the sponsors provided

How to reproduce

Get a User class for existing user with sponsors, modify the sponsors list adding a new sponsors, set and update user.

SDK Version

6.13.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output

Click to expand log ```

Exception in thread "main" com.microsoft.graph.beta.models.odataerrors.ODataError: The context URL 'https://graph.microsoft.com/beta/$metadata#users(sponsors())/$entity' is invalid.
at com.microsoft.graph.beta.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:212)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:674)
at com.microsoft.kiota.ApiExceptionBuilder.(ApiExceptionBuilder.java:26)
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:673)
at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:281)
at com.microsoft.graph.beta.users.item.UserItemRequestBuilder.patch(UserItemRequestBuilder.java:1138)
at com.microsoft.graph.beta.users.item.UserItemRequestBuilder.patch(UserItemRequestBuilder.java:1122)
at xxx.MSEntraService.updateUser(MSEntraService.java:86)
at xxx.Main.main(Main.java:147)

</details>


### Configuration

Windows 11 x64

### Other information

Any interaction with sponsors throw an error
@Ndiritu
Copy link
Contributor

Ndiritu commented Jul 15, 2024

Hi @Doc94
The API supports different operations to assign/remove sponsors from a user.
Please see:
https://learn.microsoft.com/en-us/graph/api/user-post-sponsors?view=graph-rest-1.0&tabs=http
https://learn.microsoft.com/en-us/graph/api/user-delete-sponsors?view=graph-rest-1.0&tabs=http

A work-around using the SDK:

User sponsor = new User();
sponsor.setId("");

graphClient.users().withUrl(
    client.getRequestAdapter().getBaseUrl() + "users/{userId}/sponsors/$ref"
).post(sponsor);

Let me know if this works

@Doc94
Copy link
Author

Doc94 commented Jul 15, 2024

Hi @Doc94 The API supports different operations to assign/remove sponsors from a user. Please see: https://learn.microsoft.com/en-us/graph/api/user-post-sponsors?view=graph-rest-1.0&tabs=http https://learn.microsoft.com/en-us/graph/api/user-delete-sponsors?view=graph-rest-1.0&tabs=http

A work-around using the SDK:

User sponsor = new User();
sponsor.setId("");

graphClient.users().withUrl(
    client.getRequestAdapter().getBaseUrl() + "users/{userId}/sponsors/$ref"
).post(sponsor);

Let me know if this works

i test that and give me an error.

Exception in thread "main" com.microsoft.graph.beta.models.odataerrors.ODataError: An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected.
	at com.microsoft.graph.beta.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
	at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:212)
	at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:674)
	at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
	at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:673)
	at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:281)
	at com.microsoft.graph.beta.users.UsersRequestBuilder.post(UsersRequestBuilder.java:165)
	at com.microsoft.graph.beta.users.UsersRequestBuilder.post(UsersRequestBuilder.java:149)

i test this based in another methods (not the perfect code...)

public void addSponsor(@NotNull String userId, @NotNull String sponsorId) {
        Preconditions.checkArgument(true, "Group ID cannot be null");
        com.microsoft.graph.beta.models.ReferenceCreate referenceCreate = new com.microsoft.graph.beta.models.ReferenceCreate();
        referenceCreate.setOdataId("https://graph.microsoft.com/v1.0/users/" + sponsorId);

        HashMap<String, Object> requestParameters = new HashMap<>();
        requestParameters.put("baseurl", "https://graph.microsoft.com/beta");
        requestParameters.put("user%2Did", userId);
        RequestInformation requestInformation = new RequestInformation(HttpMethod.POST, "{+baseurl}/users/{user%2Did}/sponsors/$ref", requestParameters);
        requestInformation.headers.tryAdd("Accept", "application/json");
        requestInformation.setContentFromParsable(this.graphClient.getRequestAdapter(), "application/json", referenceCreate);

        HashMap<String, ParsableFactory<? extends Parsable>> errorMapping = new HashMap();
        errorMapping.put("XXX", ODataError::createFromDiscriminatorValue);
        this.graphClient.getRequestAdapter().sendPrimitive(requestInformation, errorMapping, Void.class);
    }

and this works but pretty sure im make unnecesary things for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants