powershell - Determine folder IDs with Invoke-RestMethod on Office 365 -
when provide in powershell: invoke-restmethod -uri "https://outlook.office365.com/api/v1.0/users/andrew.stevens@mydomain.com/folders/"
-credential $cred | foreach-object{$_.value |select displayname,id}
i determine folder ids, not folders visible. how complete listing of folders (the 1 particular want recoverable items). i'm thinking once id can see messages folder contain..?
thanks
//a
did mean deleted items folder? if understand correctly, should listed rest calling. , can use well-known folder names: deleteditems messages. here example reference:
get: https://outlook.office.com/api/v2.0/me/mailfolders/deleteditems/messages
update
to use office 365 rest api, need use bearer token need register app first. below sample access token via powershell reference(refer obtaining access token):
#region construct azure datamarket access_token #get clientid , client_secret https://datamarket.azure.com/developer/applications/ #refer obtaining accesstoken (http://msdn.microsoft.com/en-us/library/hh454950.aspx) $clientid = '<your value here registered application>' $client_secret = ‘<your registered application client_secret>' # if clientid or client_secret has special characters, urlencode before sending request $clientidencoded = [system.web.httputility]::urlencode($clientid) $client_secretencoded = [system.web.httputility]::urlencode($client_secret) #define uri azure data market $uri = "https://datamarket.accesscontrol.windows.net/v2/oauth2-13" #define body of request $body = "grant_type=client_credentials&client_id=$clientidencoded&client_secret=$client_secretencoded&scope=http://api.microsofttranslator.com" #define content type request $contenttype = "application/x-www-form-urlencoded" #invoke rest method. handles deserialization of json result. less effort invoke-webrequest $admauth=invoke-restmethod -uri $uri -body $body -contenttype $contenttype -method post #construct header value access_token recieved $headervalue = "bearer " + $admauth.access_token #endregion #region construct , invoke rest request microsoft translator service [string] $text = "use pixels express measurements padding , margins."; [string] $textencoded = [system.web.httputility]::urlencode($text) [string] $from = "en"; [string] $to = "de"; [string] $uri = "http://api.microsofttranslator.com/v2/http.svc/translate?text=" + $text + "&from=" + $from + "&to=" + $to; $result = invoke-restmethod -uri $uri -headers @{authorization = $headervalue} #endregion $result.string.'#text'
after access token, can use sample below make rest call:
$uri ="https://outlook.office.com/api/v2.0/me/mailfolders/deleteditems/messages" $accesstoken='' invoke-restmethod -uri $uri -headers @{authorization=("bearer {0}" -f $accesstoken)}
links below helpful learning office 365 rest api:
Comments
Post a Comment