microsoftgraph / microsoftgraph/msgraph-sdk-java

"Empty Payload. JSON content expected." when posting a comment with SDK v6

Đang mở
#2,131 4 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

dependency:metadata type:bug
Ngôn ngữ chính
Java
Star
444
Fork
154
Merge trung bình
18 giờ 28 phút
Pull request đã merge (30 ngày)
4

Mô tả

Describe the bug

"Empty Payload. JSON content expected." error is thrown when trying to add a comment on an Alert v2.

com.microsoft.graph.models.odataerrors.ODataError: Empty Payload. JSON content expected.
	at com.microsoft.graph.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.sendCollection(OkHttpRequestAdapter.java:200)
	at com.microsoft.graph.security.alerts_v2.item.comments.CommentsRequestBuilder.post(CommentsRequestBuilder.java:72)
	at com.microsoft.graph.security.alerts_v2.item.comments.CommentsRequestBuilder.post(CommentsRequestBuilder.java:56)

HTTP response status code is 400 "bad request".

Expected behavior

A comment is created on the alert, without any error.

For instance, posting the same request with Curl works perfectly:

curl -X POST \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "@odata.type": "microsoft.graph.security.alertComment",
    "comment": "Your comment here"
  }' \
  "https://graph.microsoft.com/v1.0/security/alerts_v2/{alertId}/comments"
How to reproduce

I followed the instructions from the documentation (https://learn.microsoft.com/en-us/graph/api/security-alert-post-comments?view=graph-rest-1.0&tabs=java):

GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);

com.microsoft.graph.models.security.AlertComment alertComment = new com.microsoft.graph.models.security.AlertComment();
alertComment.setOdataType("microsoft.graph.security.alertComment");
alertComment.setComment("Demo for docs");
var result = graphClient.security().alertsV2().byAlertId("{alert-id}").comments().post(alertComment);

but converted that code into Kotlin.
The post() method, contrary to the documentation need a list of comments as input instead of a single comment.

val comment = AlertComment()
comment.odataType = "microsoft.graph.security.alertComment"
comment.comment = "my comment"
graphClient.security().alertsV2().byAlertId(alertId).comments().post(listOf(comment))

Debugging the request, I can see that the payload send by the SDK is [{"comment":"my comment","@odata.type":"microsoft.graph.security.alertComment"}] instead of {"comment":"my comment","@odata.type":"microsoft.graph.security.alertComment"} as it should be.

SDK Version

6.13.0

Latest version known to work for scenario above?

unknown

Known Workarounds

No response

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu tại security/alerts_v2 item comments CommentsRequestBuilder.post, sử dụng stack trace và reproduction của AlertComment để truy vết quá trình tuần tự hóa request. So sánh body của SDK với payload của curl; hoàn tất khi việc đăng một AlertComment gửi một JSON object thay vì một mảng một phần tử và tạo comment thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.