API via Python to create an Asset Group Error Message

Attempting to use the API via Python to create an Asset Group, but getting an error on the initial step (creating an empty static AG):

‘{\n “status” : 500,\n “message” : “An unexpected error occurred. See the log file for more information or contact support.”,\n “links” : [ {\n “href” : “https://:3780/api/3/asset_groups”,\n “rel” : “self”\n } ]\n}’

Reviewed the access.log file but only found this line:
2020-03-27T15:52:08 [INFO] [Thread: http-nio-3780-exec-4=/api/3/asset_groups] [Method: POST] [URI: /api/3/asset_groups] [Protocol: HTTP/1.1] [IP:] [Port: 10782] [Referer: ] [User-Agent: python-requests/2.21.0] [Authentication: Basic] [Principal: “apitest”] [Session: null] [Silo ID: default] [User ID: 80] [Status: 500] [Started: 2020-03-27T15:52:08] [Duration: 0:00:00.139] Request handled.

import requests
import json
from base64 import b64encode

url = “https://:3780/api/3/asset_groups”

userAndPass = b"apitest:"

b64Val = b64encode(userAndPass).decode()

headers = { ‘Authorization’ : ‘Basic %s’ % b64Val, ‘Content-Type’ : ‘application/json’ }

agData = {“description”: “Assets that can be exploited by a novice.”, “name”: “Exploitable by Novice”, “type”: “static”}

r = requests.post(url, headers=headers, data=json.dumps(agData), verify=False)

Alternately, if I try submitting it without using json.dumps() (submitting agData raw), I get this error:

‘{\n “status” : 400,\n “message” : “The JSON input is invalid at line 1, column 13. Details: Unrecognized token ‘description’: was expecting (‘true’, ‘false’ or ‘null’).”,\n “links” : [ {\n “href” : “https://:3780/api/3/asset_groups”,\n “rel” : “self”\n } ]\n}’

Any assistance identifying what I’m doing wrong will be appreciated. Thanks.

In order to accomplish this, you will need to create an asset group with no filters applied to the Search Criteria. A searchCriteria with an empty list of filters will need to be defined similar to the one below:

	"name": "Empty asset group",
	"type": "static",
	"searchCriteria": {
		"match": "all",
		"filters": []

With the empty filters list, no assets will be matched resulting in an empty asset group. Hope this helps!


To clarify/confirm, he is trying to create a static AG, not a dynamic one. Is searchcriteria still required for a static asset group?

That is correct, a static asset group uses the filter to define the scope during creation. Once it is created it will remain static, unlike a dynamic asset group. You will need to define the type and searchCriteria for both asset group types.