Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Update Sharepoint Managed Meta Data Field from Microsoft Graph Explorer

I'm trying to update the fields associated with a list item via Graph Explorer, https://developer.microsoft.com/en-us/graph/graph-explorer (or a REST API call). For one of the fields, its value can be one item from a term set (managed meta data). I can see each of the elements in the term set and get each termguid when I visit https://XXX.sharepoint.com/Lists/TaxonomyHiddenList/AllItems.aspx.

I'm trying to do a PATCH request with a URL of something like https://graph.microsoft.com/beta/sites/XXX.sharepoint.com,FOO,BAR/drive/root/children/Test%20Document.txt/listItem/fields (or https://graph.microsoft.com/v1.0/sites/XXX.sharepoint.com,FOO,BAR/drive/list/items/1/fields) to identify the fields associated with a specific item

To update the CakeType field, I've set the request body to the following:

{
    "CakeType": {
        "Label": "Apple",
        "TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
        "WssId": -1
    }
}

When I then press the Run Query button, I get an InvalidClientQueryException with a message of "A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either specified in the payload, explicitly by the caller or implicitly inferred from the parent value."

So, I've been trying to figure out what datatype to specify and how to... In various examples online, I've seen adding a field named __metadata and others adding @odata.type, like [email protected] for the case here. I've tried adding these lines within the CakeType JSON and outside it, for the whole structure. Neither worked...

{
    "CakeType": {
        "__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
        "Label": "Apple",
        "TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
        "WssId": -1
    }
}

or

{
    "__metadata" : {"type" : "SP.Taxonomy.TaxonomyFieldValue" },
    "CakeType": {
        "Label": "Apple",
        "TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
        "WssId": -1
    }
}

I've also tried using the field name in the type which I thought I saw somewhere...

"__metadata" : {"type" : "SP.Data.CakeType" },

and tried

"[email protected]" : "SP.Taxonomy.TaxonomyFieldValue" ,
"[email protected]" : "SP.Data.CakeType",
"@odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,

The only things that gave a different error message was when I put "[email protected]" : "SP.Taxonomy.TaxonomyFieldValue" , immediately after the opening { or without the CakeType part within the CakeType...

{
    "[email protected]" : "SP.Taxonomy.TaxonomyFieldValue" ,
    "CakeType": {
        "Label": "Apple",
        "TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXX",
        "WssId": -1
    }
}

and

{
    "CakeType": {
        "@odata.type" : "SP.Taxonomy.TaxonomyFieldValue" ,
        "Label": "Apple",
        "TermGuid": "3a3ad73f-94ca-4d1e-a25c-XXXXX",
        "WssId": -1
    }
}

Each gave an error of "A type named 'SP.Taxonomy.TaxonomyFieldValue' could not be resolved by the model. When a model is available, each type name must resolve to a valid type."

This makes me think that I have the right field name but the wrong type...

So... what should I be naming the type so I can update the managed meta data field? or... what must the JSON be if the above structure is so far off... or how can I update the field strictly using the Graph API.

Thanks.

I thought looking at schema extensions might help (GET https://graph.microsoft.com/v1.0/schemaExtensions) but it didn't...

Ultimately, I'm trying to update the managed meta data field from Java with the classes in com.microsoft.graph.... so if I can figure out the right stuff with Graph Explorer, I can then move over to Java. I've seen some examples of such in other languages but can't figure out the right way to do same in Java.

like image 816
jjaazz Avatar asked Mar 06 '19 22:03

jjaazz


2 Answers

Here is how I was finally able to do this. First you need the id of the hidden field which is the displayName corresponding to your field CakeType which should be CakeType_0.
I used this REST call to get find the id:

https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items?expand=hidden

This will return all your fields and you want the one with the _0 suffix:

..."displayName": "Cake_0",...

"name": "d39a5181f12f41a483acb1a4e47477b1"...

It is this name id you need to use to update the field.

So then the PATCH call on your item is like this:

https://graph.microsoft.com/v1.0/sites/{sitid}/lists/{listid}/items/{itemid}

Then the payload syntax is like this:

{"{FieldID}":"{TermNumber};#{Term}|{TermGuid}"}

So it would look like this (assuming Apple is the 4th tag although I think -1 might work there too):

{"d39a5181f12f41a483acb1a4e47477b1":"4;#Apple|3a3ad73f-94ca-4d1e-a25c-XXXX"}

For more than one tag separate them with ;# all within the same quoted string

like image 147
Ken Bragg Avatar answered Jan 02 '23 20:01

Ken Bragg


I was having the same issue, and found this: https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests/suggestions/33421180-support-for-setting-sharepoint-managed-metadata-t

The feature request:

Support for setting SharePoint Managed Metadata (taxonomy) column values and other complex column types on items via the Graph API

The response:

Thank you for your feedback! This work is on the backlog and currently isn’t scheduled. The feature will be updated here once dev work has started. -EY

like image 27
JBart Avatar answered Jan 02 '23 18:01

JBart