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

4

8

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.

Calondra answered 6/3, 2019 at 22:50 Comment(4)
One other thing I tried to do is append _0 to field name and place all the args in a | separated string. Haven't figureed out what to append _0 to as in the case above, just adding after CakeType like CakeType_0 didn't work.Calondra
Hello @jjaazz, did you manage to update field? I think i have same issue nowAffricate
@user201202 NopeCalondra
@Calondra did you managed to get this to work? I'm currently facing the same issue and I can't figure out how to update the record correctly.Varden
G
4

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

Gregor answered 3/7, 2020 at 13:2 Comment(5)
Dude, I think you're getting me to almost where I need to be. Though, instead of /items?expand=hidden, I think it may be /columns?expand=hidden. I have no idea how you found the expand=hidden.Committeeman
Yes I think asking for items will get you the field ids and the hidden field ids. But to get the individual terms and their ids I think you need to have an item already in your list with those tags applied and then query that specific item. Then you have both things you need, the field id and the terms and their ids. I cannot see any way to get the tags and their ids without having them applied to at least one item.Gregor
You guys rock! I was looking for a way to clear taxonomy field and only this trick helped.Corena
Hey, guys! this helped a lot. To get the field id I do the following: 1- query the columns via /sites/site-id/lists/list-id/columns 2- you'll see the columns with Id formats as "a8835f68-c20c-4206-aece-fe19c92c22ac" 3- You then have to remove the dashes (-) so as to format the column Id like "a8835f68c20c4206aecefe19c92c22ac" 4- format the value as @KenBragg points: "{TermNumber};#{Term}|{TermGuid}}" PS: This works, but I haven't tried it with fields that support multiple taxonomy valuesWean
Hi, how can we update with multiple tags? thanks you a lotPendent
W
1

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

Whirly answered 19/7, 2019 at 18:31 Comment(0)
J
0

To get the {fieldid} I query the columns via https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/columns?expand=Hidden and search for the columnname including "_0" as describe above. I used the id behind the "name" property.

In order to get the proper payload syntax for the json i did use the following: GET https://graph.microsoft.com/v1.0/sites/{siteid}/lists/{listid}/Items/{itemid}?expand=fields(select={fieldid})

Strange that there is no uniform way for everyone, but it its possible to change managed metadata through microsoft.graph!

Jubbah answered 20/9, 2023 at 14:15 Comment(0)
T
0

Had a similar problem creating a document set and updating managed metadata.

It seems to me that Graph API doesn't support managed metadata but sharepoint REST API does.

I've used both to create a document set (Graph API) and update managed metadata (sharepoint REST API) which included getting two separate access tokens for each API.

in my Permit App I needed to include a type which was the column that had managed metadata.

// This is the format to update managed metadata in SharePoint, including the required __metadata


const updatePayload = {
  __metadata: { type: 'SP.Data.ResDevPermitItem' },
  Permit_x0020_Type: {
    "__metadata": { "type": "SP.Taxonomy.TaxonomyFieldValue" }, // Managed Metadata specific type
    "Label": permitType.Label,
    "TermGuid": permitType.TermGuid,
    "WssId": -1
  }
};

// Make the request to update the Permit Type metadata via SharePoint REST API
await axios.post(sharepointRestUrl, updatePayload, { headers });
Threesquare answered 1/10 at 22:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.