1

I've been working with the TermStore in Microsoft Graph, using the official documentation I've managed to get a CRUD system of Terms. The whole point of the TermStore is using these terms with files, so I thought it would be also easy to add those terms into files, foolish of me to think that. I've tried to search, and I didn't find any way to do that, I know using the SharePoint REST API or CSOM or PnP is possible, but it feels to me very anti-intuitive, why Microsoft would give the possibility to perform CRUD operations on terms, but then there is no way to add those terms into files? Maybe it's just me that I didn't find how to do it.

This is what I've tried:

If I make this HTTP call, the object that I receive doesn't show the Taxonomy property, so I can't make a PATCH call to modify that value because it simply doesn't appear.

GET https://graph.microsoft.com/v1.0/sites/{site-id}/drive/items/{item-id}?expand=listItem

And if I do this HTTP call, the object has the Taxonomy property

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/Documents/items/{item-id}?expand=fields

So I've tried to make a PATCH, sending this to the body

{
    "fields": {
        "TaxKeyword@odata.type": "#Collection(microsoft.graph.Json)",
        "TaxKeyword": [
            {
                "Label": "Test1",
                "TermGuid": "1b20b62d-7ee9-4f55-9ecf-88e622a3f7d7"
            }
        ]
    }
}

(I am using an existing Term that I've created with the CRUD system, but I don't know how to get the WssId, I am not sure if it is necessary or if it is even possible to obtain it)

But it appears the generic error "invalidRequest".

And is not a problem of permissions, my app has Files.ReadWrite.All, Sites.ReadWrite.All and TermStore.ReadWrite.All

I hope that there is a solution, and it's just me that I can't search well

Thank you

martirodm
  • 33
  • 7

1 Answers1

1

This works for me for the column with the taxonomy property that allows only one value:

First, you need to know the name of the hidden column associated with your column TaxKeyword

GET https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/columns?$select=hidden,id,name,displayName

Find a column TaxKeyword_0 and use its id in the PATCH request:

PATCH https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items/{item_id}/fields
{
    "hidden_column_id": "-1;#'TermName'|{TermGuid}"
}

Also this should be valid request body

{
    "hidden_column_id": "TermName|TermGuid"
}

Example of the body in my case:

{
    "a2e29228210545d49caf74aef41dea60": "-1;#'senior software engineer'|{5e6730d0-86bf-4913-bfa3-f7369e5bade4}"
}

or

{
  "a2e29228210545d49caf74aef41dea60": "DevOps|c1276249-3b86-49bd-af51-d89cc2deeac2"
}

If the column allows multiple values

PATCH https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items/{item_id}/fields
{
    "hidden_column_id": "Term1|Term1Guid;Term2|Term2Guid"
}

Example of the body in my case:

{
    "o739791951f4466caffa4beeee1091f2": "B_Mala|10e9cc83-b5a4-4c8d-8dab-4ada1252dd70;B_Zadni|2cae6c6a-9bb8-4a78-afff-81b88e735fef"
}
user2250152
  • 14,658
  • 4
  • 33
  • 57
  • Yes, it seems that I can not update this field... I really don't understand the point of giving the ability of performing CRUD operations on the TermStore but then you can not do nothing with those terms, it's pointless... – martirodm Jul 26 '23 at 10:28
  • @Martigeosys Found solution for taxonomy column that allows only one value to be set. Will try for taxonomy column with multiple values – user2250152 Jul 26 '23 at 10:35
  • Wow, Thank you! But it doesn't appear to me the hidden column, it appears the next ones: TaxKeyword, TaxKeywordTaxHTField and TaxCatchAll, both of these last two are hidden. But even so if I use their name (because the id appears to me that is not recognized) it says to me that it's an Invalid Request. I've tried both options that you mentioned but nothing. – martirodm Jul 26 '23 at 12:49
  • @Martigeosys Maybe I don't have exactly the same settings for the TaxKeyword column. Could you please share how did you create the taxonomy column? – user2250152 Jul 26 '23 at 12:56
  • 1
    Long story short, I was working with Enterprise Keywords, because I thought it was the same. Now I've created a column for the TaxKeywords and works fine! Thank you so much for your help – martirodm Jul 26 '23 at 14:42