SOLVED

Error calling api.admin.microsoftonline

%3CLINGO-SUB%20id%3D%22lingo-sub-854047%22%20slang%3D%22en-US%22%3EError%20calling%20api.admin.microsoftonline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-854047%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%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%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fmytenant-admin.sharepoint.com%26nbsp%3B-Credential%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmytenant-admin.sharepoint.com%26nbsp%3B-Credential%3C%2FA%3E%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%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%3BOffice%20Discovery%20Service%20API%20will%20be%20deprecated%2C%20but%20do%20it%20include%20the%20Office%20365%20Management%20APIs%20also%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%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%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20idea%20about%20what%20could%20be%20happening%3F%3C%2FP%3E%3CP%3EThanks%20in%20advance!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-854047%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eservice%20health%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-863110%22%20slang%3D%22en-US%22%3ERe%3A%20Error%20calling%20api.admin.microsoftonline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-863110%22%20slang%3D%22en-US%22%3E%3CP%3ESame%20problem%20here!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-867613%22%20slang%3D%22en-US%22%3ERe%3A%20Error%20calling%20api.admin.microsoftonline%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-867613%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F155009%22%20target%3D%22_blank%22%3E%40Bryan%20Segura%20Duche%3C%2FA%3E%26nbsp%3B%20And%20it's%20started%20working%20again.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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?

Thanks in advance!

2 Replies
Highlighted

Same problem here!

Highlighted
Solution

@Bryan Segura Duche  And it's started working again.