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

Create new ApprovalItem - error response : malformed or incorrect #943

Open
raclettierer opened this issue Nov 19, 2024 · 3 comments
Open
Labels

Comments

@raclettierer
Copy link

Describe the bug

I submit a new approvalitem. The api response that the message are malformed or incorrect.

The body of the request looks like following json. The problem is that there is an additional odata type information.

{
    "allowEmailNotification": true,
    "approvalType": "basic",
    "approvers": [
        {
            "@odata.type": "#microsoft.graph.approvalIdentitySet",
            "user": {
                "displayName": "Alex Wilber",
                "id": "9a033c37-4b75-4a89-87f6-8cd7f5b66026"
            }
        }
    ],
    "description": "Details",
    "displayName": "Title of approval 22"
}

Expected behavior

Ignore the odata type by converting the object to a json string
"@odata.type": "#microsoft.graph.approvalIdentitySet",

How to reproduce

var requestBody = new ApprovalItem
  {
      DisplayName = "Title of approval 22",
      Description = "Details",
      ApprovalType = ApprovalItemType.Basic,
      AllowEmailNotification = true,
      AllowCancel = true,                        
      Approvers = new List<ApprovalIdentitySet>
      {
          new ()
          {
              User = new Identity
              {
                  Id = "9a033c37-4b75-4a89-87f6-8cd7f5b66026",
                  DisplayName= "Alex Wilber"
              },
          }
      }
  };
  var result = await graphBetaClient.Solutions.Approval.ApprovalItems.PostAsync(requestBody)

SDK Version

5.86.0

Latest version known to work for scenario above?

No response

Known Workarounds

Debug output

Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_
@raclettierer raclettierer added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 19, 2024
@andrueastman
Copy link
Member

Transferring to the beta repo as this beta SDK related

@andrueastman andrueastman transferred this issue from microsoftgraph/msgraph-sdk-dotnet Dec 5, 2024
@andrueastman
Copy link
Member

Thanks for raising this @raclettierer

This looks to probably be a metadata/conversion side issue as the constructor initializes a value for the same here.

OdataType = "#microsoft.graph.approvalIdentitySet";

In the meantime, you could probably work around this by doing the following.

SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories["application/json"] = new JsonSerializationWriterFactory(); // don't serialize null values
var requestBody = new ApprovalItem
{
    DisplayName = "Title of approval 22",
    Description = "Details",
    ApprovalType = ApprovalItemType.Basic,
    AllowEmailNotification = true,
    AllowCancel = true,
    Approvers = new List<ApprovalIdentitySet>
  {
      new ()
      {
          OdataType = null, // set value to null so that its ingored.
          User = new Identity
          {
              Id = "9a033c37-4b75-4a89-87f6-8cd7f5b66026",
              DisplayName= "Alex Wilber"
          },
      }
  }
};

@andrueastman andrueastman added Status: Needs investigation and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned labels Dec 5, 2024
@raclettierer
Copy link
Author

@andrueastman I try your workaround, but the result is not as expected :-)

"approvers":[{
"@odata.type":null,
"@odata.type":null,
"user":{

Do you have any other ideas ?

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

No branches or pull requests

2 participants