Hi All,
Has anyone successfully created a Python script to query the Sysaid API? I’ve been struggling to get this working … POSTMAN is working fine though.
Just wondered if anyone had a sample script i could look at.
Thanks,
Hi All,
Has anyone successfully created a Python script to query the Sysaid API? I’ve been struggling to get this working … POSTMAN is working fine though.
Just wondered if anyone had a sample script i could look at.
Thanks,
Best answer by cary512
I just posted some python code a few hours ago regarding a problem with attachments. That could get you started. I didn’t include a login routine so you’re going to get a 401 response every time, until you handle that. You could merge that code with the code below and should be able to get it working. I extracted this from a larger codebase so there’s probably some bugs. At the very least I think I used “/tmp” for the cookie path in that other code instead of the account-specific path found here. Good luck!
import urllib
username = "my-sysaid-username"
rawpass = "my-plaintext-sysaid-password"
def login():
global headers
headers = { 'Content-Type': 'application/json' }
logininfo = {'user_name': username, 'password': urllib.parse.quote_plus(rawpass)}
saurl = "https://%s.sysaidit.com/api/v1/login" %account
response = session.post(url=saurl, headers=headers, json=logininfo)
if response['status_code'] == 200:
# login successful - store the session id
scresponse = save_cookie(response['headers'])
return scresponse
return False # login failed
def save_cookie(rheaders):
global headers
cookiestr = str(rheaders['set-cookie'])
cookie = cookiestr.split(';')[0]
headers = { 'Cookie': cookie, 'Content-Type': 'application/json' }
os.makedirs("/tmp/sysaid/%s/state" %account, exist_ok=True)
with open('/tmp/sysaid/%s/state/jsessionid' %account, 'w') as fd:
fd.write(cookie)
fd.write('\n')
fd.close()
return True
return False
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.