0

I am trying to update a SharePoint list. More precisely, a hyperlink custom field.

fields returned

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:

enter image description here

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

4
  • Try to use Graph Explorer to check whether the update of the hyperlink field is supported by the Graph API. The issue may not be related to the Graph SDK. Commented Jul 27 at 8:28
  • Ok, but how cam I check if I don't know what the structure should be? Maybe I need to add some extra details. I have found something similar gor the lookup, where an odata type param needs to be supplied in the structure. But no documentation for that either. Maybe this needs something similar, maybe something else is the culprit. I can't test without reference. Commented Jul 27 at 9:33
  • The correct structure for hyperlink is "{FieldName}": { "Description": "https://example.com/img1.jpg", "Url": "https://example.com/img1.jpg" }, JSON object with the description and url properties. There is lack of documentation for SharePoint list fields. Commented Jul 27 at 9:54
  • Well, that structure is rejected. I have added the request and the response above. Commented Jul 28 at 8:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.