SOLVED

REST API to apply a retention Label

%3CLINGO-SUB%20id%3D%22lingo-sub-277778%22%20slang%3D%22en-US%22%3EREST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-277778%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20there%20a%20REST%20method%20to%20apply%2Fupdate%20a%20retention%20label%20on%20a%20file%20in%20a%20library%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-277778%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-343948%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-343948%22%20slang%3D%22en-US%22%3EGreat%20stuff%2C%20Thank%20you!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-343900%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-343900%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20we've%20made%20the%20following%20announcements%20on%20January%2029th%3A%26nbsp%3B%3CA%20title%3D%22Simplify%20processes%20and%20meet%20your%20requirements%20with%20new%20records%20management%20updates%22%20href%3D%22https%3A%2F%2Faka.ms%2F1.29ADGupdates%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESimplify%20processes%20and%20meet%20your%20requirements%20with%20new%20records%20management%20updates%3C%2FA%3E%20which%20includes%20document%20REST%20API%20for%20event%20based%20retention%3A%20%3CA%20title%3D%22Automate%20event-based%20retention%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fautomate-event-driven-retention%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fsecuritycompliance%2Fautomate-event-driven-retention%3C%2FFONT%3E%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-343595%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-343595%22%20slang%3D%22en-US%22%3EAny%20update%20on%20this%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-287974%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287974%22%20slang%3D%22en-US%22%3E%3CP%3Ethanks%2C%20we%20are%20planning%20to%20release%20a%20REST%20API%20which%20will%20create%20the%20event-based%20retention%20by%20the%20end%20of%20year%20so%20stay%20tune%20(see%20this%20demo%20we%20did%20at%20Ignite%3A%26nbsp%3B%3CFONT%3E%3CA%20href%3D%22https%3A%2F%2Fyoutu.be%2FgBNcHJ7ERl8%3Ft%3D2848%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fyoutu.be%2FgBNcHJ7ERl8%3Ft%3D2848%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-287461%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287461%22%20slang%3D%22en-US%22%3E%3CP%3ENot%20yet.%20Could%20not%20spend%20too%20much%20time%20on%20it%20yet.%20But%20still%20keen%20to%20find%20it%20out.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-287431%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287431%22%20slang%3D%22en-US%22%3E%3CP%3EDid%20you%26nbsp%3Bever%20find%20out%20if%20there%20is%20a%20REST%20API%20that%20could%20be%20used%20for%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-284398%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-284398%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F67%22%20target%3D%22_blank%22%3E%40Christophe%20Fiessinger%3C%2FA%3E%26nbsp%3BI%20have%20site%20with%20retention%20Labels%20published%20on%20it.%20The%20document%20library%20in%20question%20uses%20these%20labels.%20There%20is%20a%20default%20label%20set%20as%20well.%20Based%20on%20the%20type%2Fcontent%20of%20document%20users%20upload%20they%20change%20the%20label%20value%20to%20a%20more%20relevant%20one.%3C%2FP%3E%3CP%3EI%20was%20trying%20to%20automate%20some%20aspects%20of%20it%20by%20creating%20a%20Flow%20that%20will%20apply%20a%20specific%20Label%20based%20on%20lets%20say%20value%20of%20a%20column.%20Flow%20can%20call%20SharePoint%20Rest%20APIs%20easily%2C%20and%20hence%20the%20question.%3C%2FP%3E%3CP%3EDid%20not%20want%20to%20pass%20the%20call%20onto%20an%20Azure%20Function%20or%20something%2C%20but%20I%20know%20that%20is%20an%20option.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-284210%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-284210%22%20slang%3D%22en-US%22%3E%3CP%3EJoe%20can%20you%20please%20share%20the%20end%20to%20end%20scenario%20you%20are%20trying%20to%20achieve%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-277820%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-277820%22%20slang%3D%22en-US%22%3E%3CP%3EYes%2C%20I%20did%20see%20that%20it%20was%20available%20through%20CSOM%2C%20but%20I%20was%20trying%20to%20figure%20out%20what%20would%20be%20the%20REST%20endpoint%20for%20this.%20Basically%2C%20I%20was%20trying%20to%20get%20the%20field%20updated%20from%20a%20Flow.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-277818%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-277818%22%20slang%3D%22en-US%22%3EI%20think%20this%20shgould%20be%20available%20throught%20CSOM%3A%20%3CA%20href%3D%22http%3A%2F%2Fwww.myfatblog.co.uk%2Findex.php%2F2018%2F05%2Fconfiguring-default-office-365-labels-using-powershell%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.myfatblog.co.uk%2Findex.php%2F2018%2F05%2Fconfiguring-default-office-365-labels-using-powershell%2F%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-634431%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-634431%22%20slang%3D%22en-US%22%3EAnyway%20update%20on%20this%3F%20I%20need%20to%20create%20a%20SPFX%20Extensions%20CommandSet%20that%20will%20apply%20a%20retention%20label%20on%20the%20selected%20items%20in%20a%20library.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-870413%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-870413%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F281756%22%20target%3D%22_blank%22%3E%40boby5555_%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20know%20the%20name%20of%20the%20retention%20label%2C%20you%20should%20be%20able%20to%20do%20this%3A%3C%2FP%3E%3CP%3EUse%20SPHttpClient%20and%20do%20a%20POST%20request%20to%20to%26nbsp%3B%3CEM%3E%3CA%20href%3D%22https%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FsomeSite%2F_api%2Fweb%2FLists%2FGetById('someLibraryGUID')%2Fitems%2FdocumentLocalId%2FSetComplianceTag%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmytenant.sharepoint.com%2Fsites%2FsomeSite%2F_api%2Fweb%2FLists%2FGetById('someLibraryGUID')%2Fitems%2FdocumentLocalId%2FSetComplianceTag%3C%2FA%3E()%3C%2FEM%3E%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%3CBR%20%2F%3E...%20with%20a%20body%20like%20this%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22complianceTag%22%3A%20%22myLabel%22%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22isTagPolicyHold%22%3A%20%22True%22%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%22isTagPolicyRecord%22%3A%20%22True%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1049247%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1049247%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F210926%22%20target%3D%22_blank%22%3E%40Silje%20Dahl%3C%2FA%3E%26nbsp%3B%20%26nbsp%3BCan%20you%20post%20a%20working%20example%20with%20exact%20HTTP%20headers%2C%20I%20have%20been%20trying%20but%20it%20doesn't%20seem%20to%20apply.%3C%2FP%3E%3CP%3EOthers%3A%20There%20is%20a%20mention%20on%20this%20thread%20that%20this%20will%20be%20released%20as%20a%20supported%20mechanism%20in%20Flow%20by%20MS%20at%20some%20point%2C%20is%20it%20released%20now%2C%20I%20tried%20to%20find%20but%20can't%20find%20it%20yet.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1049365%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1049365%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F478681%22%20target%3D%22_blank%22%3E%40SukeshCrimson%3C%2FA%3E%26nbsp%3Bhere%20is%20my%20JSON%20code%20from%20an%20HTTP%20call%20in%20Logic%20apps.%20It's%20possible%20you%20can%20perform%20a%20similar%20call%20in%20Flow%20as%20well%2C%20but%20I%20haven't%20tried%20as%20there%20is%20no%20direct%20code%20edit%20there.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%22Apply_Label%22%3A%20%7B%0A%20%22inputs%22%3A%20%7B%0A%20%20%22body%22%3A%20%7B%0A%20%20%20%22body%22%3A%20%22%7B%5Cn'complianceTag'%3A%20'%40%7Bvariables('MyComplianceTagName')%7D'%2C%5Cn'isTagPolicyHold'%3A%20'True'%2C%5Cn'isTagPolicyRecord'%3A%20'True'%5Cn%7D%22%2C%0A%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%22Accept%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%2C%0A%20%20%20%20%22Content-Type%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%0A%20%20%20%7D%2C%0A%20%20%20%22method%22%3A%20%22POST%22%2C%0A%20%20%20%22uri%22%3A%20%22_api%2Fweb%2FLists%2FGetById('%40%7Boutputs('Library')%7D')%2Fitems(%40%7Boutputs('LocalDocId')%7D)%2FSetComplianceTag()%22%0A%20%20%7D%2C%0A%20%20%22host%22%3A%20%7B%0A%20%20%20%22connection%22%3A%20%7B%0A%20%20%20%20%22name%22%3A%20%22%40parameters('%24connections')%5B'sharepointonline'%5D%5B'connectionId'%5D%22%0A%20%20%20%7D%0A%20%20%7D%2C%0A%20%20%22method%22%3A%20%22post%22%2C%0A%20%20%22path%22%3A%20%22%2Fdatasets%2F%40%7BencodeURIComponent(encodeURIComponent(outputs('DocSite')))%7D%2Fhttprequest%22%0A%20%7D%2C%0A%20%22runAfter%22%3A%20%7B%0A%20%20%22XYZ%22%3A%20%5B%0A%20%20%20%22Succeeded%22%0A%20%20%5D%0A%20%7D%2C%0A%20%22type%22%3A%20%22ApiConnection%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%20is%20the%20input%20interpreted%20by%20Logic%20Apps%2C%20including%20the%20headers%20and%20body%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22method%22%3A%20%22post%22%2C%0A%20%20%20%20%22path%22%3A%20%22%2Fdatasets%2Fhttps%25253A%25252F%25252FmyTenant.sharepoint.com%25252Fsites%25252FmySite%2Fhttprequest%22%2C%0A%20%20%20%20%22host%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22connection%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22%2Fsubscriptions%2Fffffffff-ffff-ffff-ffff-ffffffffffff%2FresourceGroups%2FMyRG%2Fproviders%2FMicrosoft.Web%2Fconnections%2Fsharepointonline%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22body%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22body%22%3A%20%22%7B%5Cn'complianceTag'%3A%20'Exact%20label%20name'%2C%5Cn'isTagPolicyHold'%3A%20'True'%2C%5Cn'isTagPolicyRecord'%3A%20'True'%5Cn%7D%22%2C%0A%20%20%20%20%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Accept%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22method%22%3A%20%22POST%22%2C%0A%20%20%20%20%20%20%20%20%22uri%22%3A%20%22_api%2Fweb%2FLists%2FGetById('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')%2Fitems(1234)%2FSetComplianceTag()%22%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFrom%20Logic%20Apps%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1049414%22%20slang%3D%22en-US%22%3ERe%3A%20REST%20API%20to%20apply%20a%20retention%20Label%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1049414%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F478681%22%20target%3D%22_blank%22%3E%40SukeshCrimson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESeems%20my%20last%20reply%20was%20deleted%2C%20so%20I'll%20try%20reposting%20it.%20This%20is%20my%20code%20from%20Logic%20Apps%2C%20perhaps%20you%20can%20use%20it%20in%20a%20Flow%20HTTP%20call%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%22Apply_Label%22%3A%20%7B%0A%20%22inputs%22%3A%20%7B%0A%20%20%22body%22%3A%20%7B%0A%20%20%20%22body%22%3A%20%22%7B%5Cn'complianceTag'%3A%20'%40%7Bvariables('MyComplianceTagName')%7D'%2C%5Cn'isTagPolicyHold'%3A%20'True'%2C%5Cn'isTagPolicyRecord'%3A%20'True'%5Cn%7D%22%2C%0A%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%22Accept%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%2C%0A%20%20%20%20%22Content-Type%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%0A%20%20%20%7D%2C%0A%20%20%20%22method%22%3A%20%22POST%22%2C%0A%20%20%20%22uri%22%3A%20%22_api%2Fweb%2FLists%2FGetById('%40%7Boutputs('Library')%7D')%2Fitems(%40%7Boutputs('LocalDocId')%7D)%2FSetComplianceTag()%22%0A%20%20%7D%2C%0A%20%20%22host%22%3A%20%7B%0A%20%20%20%22connection%22%3A%20%7B%0A%20%20%20%20%22name%22%3A%20%22%40parameters('%24connections')%5B'sharepointonline'%5D%5B'connectionId'%5D%22%0A%20%20%20%7D%0A%20%20%7D%2C%0A%20%20%22method%22%3A%20%22post%22%2C%0A%20%20%22path%22%3A%20%22%2Fdatasets%2F%40%7BencodeURIComponent(encodeURIComponent(outputs('DocSite')))%7D%2Fhttprequest%22%0A%20%7D%2C%0A%20%22runAfter%22%3A%20%7B%0A%20%20%22XYZ%22%3A%20%5B%0A%20%20%20%22Succeeded%22%0A%20%20%5D%0A%20%7D%2C%0A%20%22type%22%3A%20%22ApiConnection%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20the%20resulting%20request%20headers%20and%20body%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22method%22%3A%20%22post%22%2C%0A%20%20%20%20%22path%22%3A%20%22%2Fdatasets%2Fhttps%25253A%25252F%25252FmyTenant.sharepoint.com%25252Fsites%25252FmySite%2Fhttprequest%22%2C%0A%20%20%20%20%22host%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22connection%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22name%22%3A%20%22%2Fsubscriptions%2Fffffffff-ffff-ffff-ffff-ffffffffffff%2FresourceGroups%2FLogicApps%2Fproviders%2FMicrosoft.Web%2Fconnections%2Fsharepointonline%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22body%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22body%22%3A%20%22%7B%5Cn'complianceTag'%3A%20'Exact%20label%20name'%2C%5Cn'isTagPolicyHold'%3A%20'True'%2C%5Cn'isTagPolicyRecord'%3A%20'True'%5Cn%7D%22%2C%0A%20%20%20%20%20%20%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Accept%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Content-Type%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22method%22%3A%20%22POST%22%2C%0A%20%20%20%20%20%20%20%20%22uri%22%3A%20%22_api%2Fweb%2FLists%2FGetById('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')%2Fitems(1234)%2FSetComplianceTag()%22%0A%20%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Is there a REST method to apply/update a retention label on a file in a library?

14 Replies
Highlighted
Highlighted

Yes, I did see that it was available through CSOM, but I was trying to figure out what would be the REST endpoint for this. Basically, I was trying to get the field updated from a Flow.

Highlighted

Joe can you please share the end to end scenario you are trying to achieve?

Highlighted

@Christophe Fiessinger I have site with retention Labels published on it. The document library in question uses these labels. There is a default label set as well. Based on the type/content of document users upload they change the label value to a more relevant one.

I was trying to automate some aspects of it by creating a Flow that will apply a specific Label based on lets say value of a column. Flow can call SharePoint Rest APIs easily, and hence the question.

Did not want to pass the call onto an Azure Function or something, but I know that is an option.

Highlighted

Did you ever find out if there is a REST API that could be used for this?

Highlighted

Not yet. Could not spend too much time on it yet. But still keen to find it out.

Highlighted
Best Response confirmed by Joe James (Occasional Contributor)
Solution

thanks, we are planning to release a REST API which will create the event-based retention by the end of year so stay tune (see this demo we did at Ignite: https://youtu.be/gBNcHJ7ERl8?t=2848

With the proliferation of data in the modern workplace, a comprehensive strategy to keep what you need and get rid of the rest is more important than ever. J...
Highlighted
Any update on this?
Highlighted

Yes we've made the following announcements on January 29th: Simplify processes and meet your requirements with new records management updates which includes document REST API for event based retention: https://docs.microsoft.com/en-us/office365/securitycompliance/automate-event-driven-retention 

Highlighted
Great stuff, Thank you!
Highlighted
Anyway update on this? I need to create a SPFX Extensions CommandSet that will apply a retention label on the selected items in a library.
Highlighted

@boby5555_ 

If you know the name of the retention label, you should be able to do this:

Use SPHttpClient and do a POST request to to https://mytenant.sharepoint.com/sites/someSite/_api/web/Lists/GetById('someLibraryGUID')/items/docum...()


... with a body like this:
{
"complianceTag": "myLabel",
"isTagPolicyHold": "True",
"isTagPolicyRecord": "True"
}
Highlighted

@Silje Dahl   Can you post a working example with exact HTTP headers, I have been trying but it doesn't seem to apply.

Others: There is a mention on this thread that this will be released as a supported mechanism in Flow by MS at some point, is it released now, I tried to find but can't find it yet. 

Highlighted

@SukeshCrimson here is my JSON code from an HTTP call in Logic apps. It's possible you can perform a similar call in Flow as well, but I haven't tried as there is no direct code edit there.

 

 

"Apply_Label": {
	"inputs": {
		"body": {
			"body": "{\n'complianceTag': '@{variables('MyComplianceTagName')}',\n'isTagPolicyHold': 'True',\n'isTagPolicyRecord': 'True'\n}",
			"headers": {
				"Accept": "application/json;odata=verbose",
				"Content-Type": "application/json;odata=verbose"
			},
			"method": "POST",
			"uri": "_api/web/Lists/GetById('@{outputs('Library')}')/items(@{outputs('LocalDocId')})/SetComplianceTag()"
		},
		"host": {
			"connection": {
				"name": "@parameters('$connections')['sharepointonline']['connectionId']"
			}
		},
		"method": "post",
		"path": "/datasets/@{encodeURIComponent(encodeURIComponent(outputs('DocSite')))}/httprequest"
	},
	"runAfter": {
		"XYZ": [
			"Succeeded"
		]
	},
	"type": "ApiConnection"
}

 

 

The following is the input interpreted by Logic Apps, including the headers and body:

 

{
    "method": "post",
    "path": "/datasets/https%253A%252F%252FmyTenant.sharepoint.com%252Fsites%252FmySite/httprequest",
    "host": {
        "connection": {
            "name": "/subscriptions/ffffffff-ffff-ffff-ffff-ffffffffffff/resourceGroups/MyRG/providers/Microsoft.Web/connections/sharepointonline"
        }
    },
    "body": {
        "body": "{\n'complianceTag': 'Exact label name',\n'isTagPolicyHold': 'True',\n'isTagPolicyRecord': 'True'\n}",
        "headers": {
            "Accept": "application/json;odata=verbose",
            "Content-Type": "application/json;odata=verbose"
        },
        "method": "POST",
        "uri": "_api/web/Lists/GetById('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')/items(1234)/SetComplianceTag()"
    }
}