Home

Error calling api.admin.microsoftonline

%3CLINGO-SUB%20id%3D%22lingo-sub-854020%22%20slang%3D%22en-US%22%3EError%20calling%20api.admin.microsoftonline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-854020%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EToday%20im%20getting%20this%20error%20calling%20the%20SHD%20admin%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CEM%3Einvoke-restmethod%20%3A%20Sendera%3AUnauthorizedUnauthorized%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CEM%3E%24cookie%20%3D%20(invoke-restmethod%20-contenttype%20%22application%2Fjson%22%20-method%20...%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CEM%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(System.Net.HttpWebRequest%3AHttpWebRequest)%20%5BInvoke-RestMethod%5D%2C%20WebException%3C%2FEM%3E%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%3CEM%3E%2B%20FullyQualifiedErrorId%20%3A%20WebCmdletWebResponseException%2CMicrosoft.PowerShell.Commands.InvokeRestMethodCommand%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20script%20was%20working%20fine%20until%20Tuesday%2C%20here%20is%20some%20code%20from%20the%20script%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-%20%24cred%20%3D%20Get-StoredCredential%20-Target%20O365User%3CBR%20%2F%3E-%20Connect-SPOService%20-Url%20%3CA%20href%3D%22https%3A%2F%2Fmytenant-admin.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmytenant-admin.sharepoint.com%3C%2FA%3E%20-Credential%20%24cred%3C%2FP%3E%3CP%3E-%20%24jsonPayload%20%3D%20(%40%7BuserName%3D%24cred.username%3Bpassword%3D%24cred.GetNetworkCredential().password%3B%7D%20%7C%20convertto-json).tostring()%3C%2FP%3E%3CP%3E-%20%24cookie%20%3D%20(invoke-restmethod%20-contenttype%20%22application%2Fjson%22%20-method%20Post%20-uri%20%22%3CA%20href%3D%22https%3A%2F%2Fapi.admin.microsoftonline.com%2Fshdtenantcommunications.svc%2FRegister%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fapi.admin.microsoftonline.com%2Fshdtenantcommunications.svc%2FRegister%3C%2FA%3E%22%20-body%20%24jsonPayload).RegistrationCookie%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20the%26nbsp%3B%3CSPAN%3EOffice%20Discovery%20Service%20API%20will%20be%20deprecated%2C%20but%20do%20it%20include%20the%20Office%20365%20Management%20APIs%20also%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20script%20is%20not%20working%20with%20a%20user%20with%20some%20privileged%20roles%20and%20with%20a%20global%20admin%20user%2C%20who%20was%20working%20until%20Tuesday.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAny%20idea%20about%20what%20could%20be%20happening%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-854020%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Bryan Segura Duche
Occasional Contributor

Hi all,

 

Today im getting this error calling the SHD admin:

 

invoke-restmethod : Sendera:UnauthorizedUnauthorized

$cookie = (invoke-restmethod -contenttype "application/json" -method ...

+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

The script was working fine until Tuesday, here is some code from the script:

 

- $cred = Get-StoredCredential -Target O365User
- Connect-SPOService -Url https://mytenant-admin.sharepoint.com -Credential $cred

- $jsonPayload = (@{userName=$cred.username;password=$cred.GetNetworkCredential().password;} | convertto-json).tostring()

- $cookie = (invoke-restmethod -contenttype "application/json" -method Post -uri "https://api.admin.microsoftonline.com/shdtenantcommunications.svc/Register" -body $jsonPayload).RegistrationCookie

 

I know the Office Discovery Service API will be deprecated, but do it include the Office 365 Management APIs also?

 

The script is not working with a user with some privileged roles and with a global admin user, who was working until Tuesday.

 

Any idea about what could be happening?

Related Conversations
Extentions Synchronization
Deleted in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
36 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
9 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies