Start a Conversation

Unsolved

A

1 Message

691

May 27th, 2022 01:00

Using OMIVV 5.4 API with Python/PowerShell

Hello,

I'm trying to login to a OMIVV 5.4 API using Python but for some unknown reason I'm not being able to get it done.

The code I'm using is the following one but it is not working for me.

My end goal is to be able to do this also from Powershell but for now I'm just trying to get this started using Python.

Is anyone able to login to a OMNI 5.4 API?

 

Thank you

Alexandre

=====

import requests

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def login_with_OMIVV (omivvIP,username,domain, password):
baseurl ="https://" + omivvIP + "/Spectre/api/rest/v1/Services/AuthenticationService/login"
postBodyData={"apiUserCredential" : {"username":username,"domain" : domain,"password" : password}}
jsonReponse = requests.post(baseurl, json=postBodyData, verify=False)
if(jsonReponse.status_code == 200):
bearerToken = jsonReponse['accessToken']
return bearerToken
else:
print("Login failed")


login_with_OMIVV("yyyyyy","admin","","xxxxxxxxx")

 

June 7th, 2022 00:00

Hello,

The issue with the code snippet shared is that it is not able to parse the response to get the access token. I've added a line of code in the snippet below and verified it to be working. Please give this snippet a go.

 

 

 

from urllib import response
import requests

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

def login_with_OMIVV (omivvIP,username,domain, password):
    baseurl ="https://" + omivvIP + "/Spectre/api/rest/v1/Services/AuthenticationService/login"
    postBodyData={"apiUserCredential" : {"username":username,"domain" : domain,"password" : password}}
    jsonReponse = requests.post(baseurl, json=postBodyData, verify=False)
    if(jsonReponse.status_code == 200):
        response = jsonReponse.json()
        bearerToken = response['accessToken']
        return bearerToken
    else:
        print("Login failed")

 

 

 

Thanks,

Adila

No Events found!

Top