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):
Error:
‘{\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: 10.11.220.79] [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.
Code:
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.