Unable to schedule scans through API

Attempting to create a schedule for a site through the API. Have followed the API documentation. However I’m getting an argument error when posting to the API. Python script snippet below. The API and authentication is working. See second snippet.

body = [{“enabled”:True, “onScanRepeat”:“restart-scan”, “start”:“2020-03-03T16:00:00-07:00”}]
a = requests.put(‘https://<CONSOLE_IP>:3780/api/3/sites/503/scan_schedules’,json=body,headers=headers)
a.text
u’{\n “status” : 400,\n “message” : “One or more arguments supplied in the request is invalid.”,\n “links” : [ {\n “href” : “https://<CONSOLE_IP>:3780/api/3/sites/503/scan_schedules”,\n “rel” : “self”\n } ]\n}’

a = requests.get(‘https://<CONSOLE_IP>:3780/api/3/sites/503/scan_schedules’,headers=headers)
a
<Response [200]>

a.text
u’{\n “resources” : [ {\n “enabled” : true,\n “id” : 1,\n “links” : [ {\n “href” : “https://<CONSOLE_IP>:3780/api/3/sites/503/scan_schedules/1”,\n “rel” : “self”\n } ],\n “nextRuntimes” : [ “2020-02-01T16:30:00Z” ],\n “onScanRepeat” : “restart-scan”,\n “scanTemplateId” : “full-audit-without-web-spider-_-custom”,\n “start” : “2020-02-01T16:30:00Z”\n } ],\n “links” : [ {\n “href” : “https://<CONSOLE_IP>:3780/api/3/sites/503/scan_schedules”,\n “rel” : “self”\n } ]\n}’

@Maria_Padilla In the request provided, this is actually attempting to update site scan schedules for the site in question. When attempting to create a Site Scan Schedule, the best approach is to use a request similar to below (curl example provided for simplicity):

curl -X POST \
  https://<CONSOLE_IP>:3780/api/3/sites/6/scan_schedules \
  -H 'Accept: application/json;charset=UTF-8' \
  -H 'Authorization: Basic <Basic auth value>' \
  -H 'Content-Type: application/json' \
  -d '{
	"enabled": true, 
	"onScanRepeat": "restart-scan",
	"start": "2020-03-28T14:00:00Z"
}'

By using a POST request, a new site scan schedule will be created. Further API documentation on this endpoint can be found here.

And another example if you wanted to update a specific Site Scan Schedule that already exists:

curl -X PUT \
  https://<CONSOLE_IP>:3780/api/3/sites/6/scan_schedules/2 \
  -H 'Accept: application/json;charset=UTF-8' \
  -H 'Authorization: Basic <Basic Auth value>' \
  -H 'Content-Type: application/json' \
  -d '{
	"enabled": true, 
	"onScanRepeat": "restart-scan",
	"start": "2020-03-28T14:00:00Z",
	"id": 2
}'

This requires the scan schedule ID to be passed in with the body of the request.

2 Likes