This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Sophos UTM API Network groups creation via Python

Hello!

I am working with Sophos UTM9 API. I am trying to create Network Group and assign members there via Python and requests.

I was able to easily get all objects/groups from device, but as soon as I try create simply from https://<url>:4444/api (POST /objects/network/group/) it gives me:

"name": "The network group object requires a Perl array for the members list attribute." (400 code).

I entered only Group name, as I want for start only create one without assigning, but also interested with member assign.

 

I didn't find anything across documentation what exactly api needs to create Groups. As I understand I need to add something X-Restd-Insert
any idea what exactly? P.S. maybe someone know how then request of creating group and assigning members can be translated to web URL link?

 

curl looks like this:

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'X-Restd-Insert: network.group' --header 'Authorization: Basic <key>' -d '{"comment":"","name":"TEST"}' 'https://<url>:4444/api/objects/network/group/'
output:
[
{
"name": "The network group object requires a Perl array for the members list attribute.",
"rights": "",
"attrs": [],
"Oattrs": [
"class",
"type"
],
"objname": "",
"del_object": "",
"ref": "",
"msgtype": "DATATYPE_OBJECT_ATTRIBUTE",
"format": "The %_O object requires %_d for the %_A attribute.",
"class": "network",
"type": "group",
"perms": "",
"never_hide": 0,
"fatal": 1
}
]%




This thread was automatically locked due to age.
  • Well, I didn't find option to create empty group, but only with objects inside.

    Looks something like this (maybe someone will need):

    def sophos_create_network_groups(NETWORK_GROUP,NETWORK_GROUP_MEMBERS):
       try:
          URL = ("https://<url>:4444/api/objects/network/group/")
          headers = {"Authorization": "Basic %s" % SOPHOS_TOKEN, 'Content-Type': 'application/json'}
          obj = {"name":NETWORK_GROUP,"members":NETWORK_GROUP_MEMBERS}
          html = requests.post(URL, headers=headers, json=obj, verify=False).content.decode("utf-8")
       except urllib.error.URLError as error:
          print ('There are error creating Groups on Sophos: '+error)
          sys.exit(0)