Hitachi Ops Center​

 View Only

 I'm trying to query the API of our Opscenter machine (for an F370).Would like to do this from Powershell.

  • Hitachi Ops Center
  • Hitachi Ops Center
Hans Lammerts's profile image
Hans Lammerts posted 11-12-2020 16:26

I was able to get a session token using the PS

Invoke-RestMethod command, but I can't seem to find how I can query the API using this session token from Powershell using a next Invoke-RestMethod command.

What would be the right syntax for the header that contains the token ?

Something like "Authorization:Session <long_token>" ? (which is not correct....😕 )


#HitachiOpsCenter
William Jansen Van Nieuwenhuizen's profile image
William Jansen Van Nieuwenhuizen

Hello

 

Yes, it's very easy. Copy and Paste from the web browser. Below a little video to show you how it's done:

https://youtu.be/a4CCpywCbiU

 

If you want to see more, feel free to reach out to the Centre of Excellence, Link in my BIO.

Hans Lammerts's profile image
Hans Lammerts

Hi William,

 

Thank you for your answer.

probably things have changed since you made the video. I cannot get the same results, in fact, all I get is Powershell presenting me with an error...

 

When I login to the Administrator GUI as sysadmin, I do see the two first lines in the network view are tokens .

The content of the first one, however, is different from what you get back.

First tokens line copied as Powershell shows this:

 

Invoke-WebRequest -Uri "https://plops300.vlkintern.nl:20961/v1/security/tokens" `>> -Method "POST" `>> -Headers @{>> "Accept"="application/json, text/plain, */*";>> "Origin"="https://plops300.vlkintern.nl:20961";>> "Authorization"="Basic c3lzYWRtaW46c3lzYWRtaW4=";>> "Sec-Fetch-Dest"="empty";>> "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36";>> "Sec-Fetch-Site"="same-origin";>> "Sec-Fetch-Mode"="cors";>> "Referer"="https://plops300.vlkintern.nl:20961/";>> "Accept-Encoding"="gzip, deflate, br";>> "Accept-Language"="en-US,en;q=0.9">> } `>> -ContentType "application/json;charset=UTF-8" `>> -Body "[]"

Running this in Powershell just gives me :

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.At line:1 char:1+ Invoke-WebRequest -Uri "https://plops300.vlkintern.nl:20961/v1/securi ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc eption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

(Note: the line break between lines 5 and 6 come from copy/paste action. This is not what I see when I do the PS call).

 

The second tokens line does contain the token returned, but here again: the copy as Powershell does not look the same as your snippet. And also fail when I run it in PS, same error.

 

Could you please enlighten me how I should tackle this situation ?

What info do you need from me so you can point me in the right direction ?

 

Thanks,

Hans

William Jansen Van Nieuwenhuizen's profile image
William Jansen Van Nieuwenhuizen

Hello

You missed a step from the video, unless you don't have a self-signed cert. You need to skip the certificate check.

Also, I was using PowerShell Core, not sure if you did this via normal PowerShell. They have a different method for allowing self signed certs.

Hans Lammerts's profile image
Hans Lammerts

Hi,

 

I did this with PS, not PS Core.

I'll try PS Core first....

 

However, the content of what I copy from the first tokens line in the network view differs substantially from what you show in your video. This is what you used in PS Core, right ? No sneaky editing in between before you show it on the video ?

😎

William Jansen Van Nieuwenhuizen's profile image
William Jansen Van Nieuwenhuizen

 

You can see the time and date in the botton right corner(made the video the same date). Pretty sure I did it in one take. So no, no sneaky editing.

 

If you want to use powershell default you can lookup how to disable self signed certificate check. I remember its a bit iffy and only for the current session. Give powershell core a go.

 

Also be sure that you login to administrator url and not ops center. Ill post a copy of my code tomorrow, so that you can give it a try too.

 

Ps, are you in the Netherlands?

Brent Lund's profile image
Brent Lund

Been a few months, not sure if you got your answer?

 

I've done the same with Python. What I suggest is using a RESTapi 'browser' such as Insomnia. This lets you verify your API calls. Then you just need to translate them to PowerShell.

 

I did the same, but to Python. Having Insomnia to verify my POST or GET was formatted correctly took Python out of the equation.