# Unable to schedule scans through API

**URL:** <https://discuss.rapid7.com/t/unable-to-schedule-scans-through-api/275>\
**Category:** API\
**Created:** [February 10, 2020, 4:43pm UTC](https://discuss.rapid7.com/t/unable-to-schedule-scans-through-api/275 "2020-02-10T16:43:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maria\_Padilla](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/maria_padilla/32/135_2.png) [@Maria\_Padilla](https://discuss.rapid7.com/u/Maria_Padilla)\
**Post date:** [February 10, 2020, 4:43pm UTC](https://discuss.rapid7.com/t/unable-to-schedule-scans-through-api/275/1 "2020-02-10T16:43:58Z")

</div>

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}’

---

<div class="post-metadata">

**Author:** ![zyoutz](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/zyoutz/32/56_2.png) [@zyoutz](https://discuss.rapid7.com/u/zyoutz)\
**Post date:** [February 10, 2020, 5:18pm UTC](https://discuss.rapid7.com/t/unable-to-schedule-scans-through-api/275/2 "2020-02-10T17:18:28Z")

</div>

@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):

```auto
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](https://help.rapid7.com/insightvm/en-us/api/index.html#operation/createSiteScanSchedule).

---

<div class="post-metadata">

**Author:** ![zyoutz](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/zyoutz/32/56_2.png) [@zyoutz](https://discuss.rapid7.com/u/zyoutz)\
**Post date:** [February 10, 2020, 5:24pm UTC](https://discuss.rapid7.com/t/unable-to-schedule-scans-through-api/275/3 "2020-02-10T17:24:20Z")

</div>

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

```auto
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.
