I am trying to update a SharePoint list. More precisely, a hyperlink custom field.
Both Server and URL are custom fields. I can read the URL, then I get:
Description: "http://x.y"
Url: "http://x.y"
I also can write any Server field, as that is a scalar string.
But it seems that the UntypedObject I am constructing is not accepted, and I get Invalid request (without any further details). I have tried both with capitalized and not capitalized names for the UntypedObject keys.
My code is as follows:
var options = new InteractiveBrowserCredentialOptions
{
TenantId = tenantId,
ClientId = clientId,
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
RedirectUri = new Uri("http://localhost")
};
var interactiveCredential = new InteractiveBrowserCredential(options);
var graphClient = new GraphServiceClient(interactiveCredential, scopes);
var items = await graphClient
.Sites[siteId]
.Lists[listId]
.Items
.GetAsync(requestConfiguration =>
{
requestConfiguration.QueryParameters.Expand = new[] { "fields" };
requestConfiguration.QueryParameters.Top = 100;
});
foreach (var item in items.Value)
{
var fields = item.Fields?.AdditionalData;
if (fields == null) continue;
if (fields.TryGetValue("URL", out var _url) && _url is UntypedObject uo) // testing read
{
foreach (var (name, node) in uo.GetValue())
{
var scalarAsString = await KiotaJsonSerializer.SerializeAsStringAsync(node);
$"{name}: {scalarAsString}".Dump();
}
continue;
}
var table = new UntypedObject(new Dictionary<string, UntypedNode>
{
["url"] = new UntypedString("whateverurl"),
["description"] = new UntypedString("whatevertext"),
});
var updateFields = new FieldValueSet
{
AdditionalData = new Dictionary<string, object>
{
["URL"] = table,
["Server"] = "whatever" // this on its own works
}
};
await graphClient
.Sites[siteId]
.Lists[listId]
.Items[item.Id]
.Fields
.PatchAsync(updateFields);
}
Request and response:
Seems to be related, but no solution there either: https://github.com/microsoftgraph/msgraph-sdk-go/discussions/687
Started github issue: https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2957
Update:
Seems to be not supported ever since, that's shameful to be straight: https://learn.microsoft.com/en-us/answers/questions/645640/how-to-update-sharepoint-list-item-hyperlink-colum
I will try this API instead: https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service?tabs=csom


"{FieldName}": { "Description": "https://example.com/img1.jpg", "Url": "https://example.com/img1.jpg" },JSON object with thedescriptionandurlproperties. There is lack of documentation for SharePoint list fields.