Hi Gareth,
Here is an example of creating a new incident via API:
from __future__ import print_function
from requests.auth import HTTPBasicAuth
import requests
import json
def main():
key_id = "-=key id=-"
key_secret = "-=key secret=-"
server = "-=IP address=-"
resource = "rest/orgs/202/incidents"
url = "https://{0}/{1}".format(server, resource)
headers = {"Content-Type": "application/json"}
name_of_the_incident="Incident from the Python script"
description_of_the_incident="Description"
auth = HTTPBasicAuth(key_id, key_secret)
req = requests.post(url, headers=headers, auth=auth, verify=False, data=json.dumps({"name":name_of_the_incident,"description":description_of_the_incident,"discovered_date":0}))
if __name__ == "__main__":
main()
------------------------------
Alexander Saulenko
------------------------------
Original Message:
Sent: Thu May 19, 2022 09:15 AM
From: Gareth Pearson
Subject: Using API key with Python requests
Hi all,
Wondering if anyone has any example code of using a SOAR API key in an integration server Python script? Previously, we've used an account but had to switch to API keys. Can't for the life of me figure out what's wrong.
import requestsapi_key_id = ''api_key_secret = ''headers = {'Content-Type': 'application/json'}auth = (api_key_id, api_key_secret)newSession = requests.Session()response = newSession.post('https://.com/rest/session',auth=auth,headers=headers,verify=False) print(response.content)
And the response is
b'{"success":false,"title":null,"message":"Internal Server Error","hints":[],"error_code":"generic"}'
Thanks in advance
------------------------------
Thanks,
Gareth
------------------------------