SOLVED

Error calling api.admin.microsoftonline

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

Same problem here!

best response confirmed by Bryan Segura Duche (Occasional Contributor)
Solution

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