SharePoint List and Hyperlink field with Microsoft Graph results in "bad request

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

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

Hướng nghiên cứu

The report includes a C# request that posts list item fields to the Microsoft Graph endpoint /sites/{siteId}/lists/{listId}/items, and says the request fails when linkPDF is included. Start by checking the documented Graph format for setting SharePoint hyperlink fields and compare it with the posted Url and Description object. Done means identifying whether the payload or SDK request handling causes the 400 and documenting a working approach.

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

Mô tả

status:waiting-for-triage type:bug
Describe the bug

I'm trying to add a record to a SharePoint List with a Hyperlink field with Microsoft Graph but I get result "bad request" json payload is {
"fields": {
"Title": "TEST",
"linkPDF": {
"Url": "https://www.microsoft.com",
"Description": "Microsoft"
}
}
}
Code is:
var fields = new JObject
{
["Title"] = entry.Title,
["Maschine"] = entry.Maschine,
["Location"] = entry.Location,
["DocumentNr"] = Convert.ToString(entry.DocumentNr),
["DocumentType"] = entry.Documenttype,
["UploadTarget"] = entry.UploadTarget,
["Message"] = entry.Message,
["TargeteMail"] = entry.TargeteMail,
["PDF"] = entry.PDF
};
if (!string.IsNullOrWhiteSpace(entry.linkPDF))
{
//fields["linkPDF"] = new JObject
//{
// ["Url"] = entry.linkPDF,
// ["Description"] = string.IsNullOrWhiteSpace(entry.PDF) ? entry.linkPDF : entry.PDF
//};
fields["linkPDF"] = new JObject
{
["Url"] = "https://www.microsoft.com",
["Description"] = "Microsoft"
};
}
string json = new JObject { ["fields"] = fields }.ToString();
Globals.CWC($"json={json}", ConsoleColor.Yellow); // zum Prüfen
var request = new RequestInformation
{
HttpMethod = Method.POST,
URI = new Uri($"https://graph.microsoft.com/v1.0/sites/{_siteId}/lists/{_listId}/items")
};
request.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(json)), "application/json");
var errorMapping = new Dictionary<string, ParsableFactory>
{
{ "4XX", ODataError.CreateFromDiscriminatorValue },
{ "5XX", ODataError.CreateFromDiscriminatorValue }
};
try
{
await _graphClient.RequestAdapter.SendAsync(request, ListItem.CreateFromDiscriminatorValue);
}
catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)

Expected behavior

normal entry in the SharePoint list with a hyperlink field (without the hyperlink field everything went fine)

How to reproduce
var fields = new JObject
  {
    ["Title"] = entry.Title,
    ["Maschine"] = entry.Maschine,
    ["Location"] = entry.Location,
    ["DocumentNr"] = Convert.ToString(entry.DocumentNr),
    ["DocumentType"] = entry.Documenttype,
    ["UploadTarget"] = entry.UploadTarget,
    ["Message"] = entry.Message,
    ["TargeteMail"] = entry.TargeteMail,
    ["PDF"] = entry.PDF
  };
  if (!string.IsNullOrWhiteSpace(entry.linkPDF))
  {
    //fields["linkPDF"] = new JObject
    //{
    //  ["Url"] = entry.linkPDF,
    //  ["Description"] = string.IsNullOrWhiteSpace(entry.PDF) ? entry.linkPDF : entry.PDF
    //};
    fields["linkPDF"] = new JObject
    {
      ["Url"] = "https://www.microsoft.com",
      ["Description"] = "Microsoft"
    };
  }
  string json = new JObject { ["fields"] = fields }.ToString();
  Globals.CWC($"json={json}", ConsoleColor.Yellow);   // zum Prüfen
  var request = new RequestInformation
  {
    HttpMethod = Method.POST,
    URI = new Uri($"https://graph.microsoft.com/v1.0/sites/{_siteId}/lists/{_listId}/items")
  };
  request.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(json)), "application/json");
  var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
      {
        { "4XX", ODataError.CreateFromDiscriminatorValue },
        { "5XX", ODataError.CreateFromDiscriminatorValue }
      };
  try
  {
    await _graphClient.RequestAdapter.SendAsync(request, ListItem.CreateFromDiscriminatorValue);
  }
  catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)
SDK Version

Graph 6.10 and Kiota 2.1.6

Latest version known to work for scenario above?

never had a running solution

Known Workarounds

no

Debug output
Click to expand log ``` Level 0 Type: System.AggregateException Message: Mindestens ein Fehler ist aufgetreten. StackTrace: bei System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) bei System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) bei System.Threading.Tasks.Task.Wait() bei e_invoicing.EInvoicingApp.Run(String[] args) in C:\VM\Kairo\e-invoicing\e-invoicing\EInvoicingApp.cs:Zeile 172. Level 1 Type: Microsoft.Kiota.Abstractions.ApiException Message: The server returned an unexpected status code and no error factory is registered for this code: 400 StackTrace: bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101. Assertion failed: System.AggregateException: Mindestens ein Fehler ist aufgetreten. ---> Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and no error factory is registered for this code: 400 bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101. --- Ende der internen Ausnahmestapelüberwachung --- bei System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) bei System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) bei System.Threading.Tasks.Task.Wait() bei e_invoicing.EInvoicingApp.Run(String[] args) in C:\VM\Kairo\e-invoicing\e-invoicing\EInvoicingApp.cs:Zeile 191. ---> (Interne Ausnahme #0) Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and no error factory is registered for this code: 400 bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101.<---
Configuration

Windows 11, newest release
x64

Other information

I've tried for 5 days now all different type of hyperlink within a sharepoint list. It works fine by entering the Hyperlink by hand, but I've never succeeded using c#

Ngôn ngữ chính
C#
Star
796
Fork
267
Merge trung bình
1 ngày 4 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

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.

Issue khác của microsoftgraph/msgraph-sdk-dotnet

Tất cả issue của microsoftgraph/msgraph-sdk-dotnet

Issue tương tự

Thêm issue về C#

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.