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

Ouverte
#3,235 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
csharp

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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#

Langage dominant
C#
Étoiles
796
Forks
267
Merge moyen
1 j 4 h
PR mergées (30 j)
5

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de microsoftgraph/msgraph-sdk-dotnet

Toutes les issues de microsoftgraph/msgraph-sdk-dotnet

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.