Skip to content

Examples

Here are examples of updating a scan request with a different test name, date, and service ID.

Request using the ‘curl’ command:

curl -X PUT "https://secure.cigital.com/api/public/v3.1/scans/TEST_2129204778/" \
-H "accept: */*" \
-H "token: e1a32d91f47dbe7603d0e00126d857e1d58856c3" \
-H "Content-Type: application/json"
-d "{\"name\":\"webTarget\",\
\"targetId\":\"TARGET_1056561617\",\
\"target\":\"https://webtarget.com\",\
\"scheduledDate\":\"2019-10-10T09:00:00+05:30\",\
\"demoDate\":\"\",\
\"assessmentType\":null,\
\"testType\":\"NON_INTRUSIVE\",\
\"riskRatingMethodology\":null,\
\"deploymentType\":\"STAGING_TESTING\",\
\"revalidationScan\":false,\
\"revalidationScanId\":null,\
\"testWindowStartTime\":0,\
\"testWindowDuration\":0,\
\"serviceId\":\"SERVICE_690378647\",\
\"flagged\":false,\
\"comments\":\"\",\
\"state\":{\"name\":\"Scheduled\",\
\"comments\":null,\
\"errorsResolved\":null},\
\"targetSubType\":\"WEB_APPLICATION\",\
\"scanId\":\"TEST_2129204778\",\
\"webType\":\"WEB_APPLICATION\"}"

Reuqest using an Apache Groovy script:

// NOTE: Environment (env) and other variables have to be
// defined beforehand.

def update_scan = httpRequest ignoreSslErrors: false,\
acceptType: 'APPLICATION_JSON',quiet: false,\
httpMode: 'PUT',customHeaders:[[name:'token',value:"${env.token}"],\
[name:'Content-Type',value:'application/json']],\
url:"${env.HostUrl}/api/public/v3/scans/"+env.testId,\
requestBody:"{\"name\":\"webTarget\",\
\"targetId\":\"TARGET_1056561617\",\
\"target\":\"https://webtarget.com\",\
\"scheduledDate\":\"2019-10-10T09:00:00+05:30\",\
\"demoDate\":\"\",\
\"assessmentType\":null,\
\"testType\":\"NON_INTRUSIVE\",\
\"riskRatingMethodology\":null,\
\"deploymentType\":\"STAGING_TESTING\",\
\"revalidationScan\":false,\
\"revalidationScanId\":null,\
\"testWindowStartTime\":0,\
\"testWindowDuration\":0,\
\"serviceId\":\"SERVICE_690378647\",\
\"flagged\":false,\
\"comments\":\"\",\
\"state\":{\"name\":\"Scheduled\",\
\"comments\":null,\
\"errorsResolved\":null},\
\"targetSubType\":\"WEB_APPLICATION\",\
\"scanId\":\"TEST_2129204778\",\
\"webType\":\"WEB_APPLICATION\"}"
println(update_scan)

Request using Java source code:

public void updateScan( String scanId,
                        String testName,
                        String targetUrl,
                        String scheduleDate ) {

    Client client = ClientBuilder.newClient();
    WebTarget target =
        client.target( MSP_URL )
              .path( "/api/public/v3/scans/" + scanId );
    String json =
        String.format( "{\"name\":\"%s\",
                         \"targetId\":\"TARGET_1056561617\",
                         \"target\":\"%s\",
                         \"scheduledDate\":'%s',
                         \"demoDate\":\"\",
                         \"assessmentType\":null,
                         \"testType\":\"NON_INTRUSIVE\",
                         \"riskRatingMethodology\":null,
                         \"deploymentType\":\"STAGING_TESTING\",
                         \"revalidationScan\":false,
                         \"revalidationScanId\":null,
                         \"testWindowStartTime\":0,
                         \"testWindowDuration\":0,
                         \"serviceId\":\"SERVICE_690378647\",
                         \"flagged\":false,
                         \"comments\":\"\",
                         \"state\":{\"name\":\"Scheduled\",
                         \"comments\":null,
                         \"errorsResolved\":null},
                         \"targetSubType\":\"WEB_APPLICATION\",
                         \"scanId\":\"TEST_2129204778\",
                         \"webType\":\"WEB_APPLICATION\"}",
                         testName,
                         targetUrl,
                         scheduleDate );
    Response response =
        target.request().accept( MediaType.APPLICATION_JSON_TYPE )
              .header( "token", MSP_TOKEN )
              .put( Entity.json( json ), Response.class );

    if (response.getStatus() == 201) {
        System.out.println( response.readEntity( String.class ) );
    } else {
        System.out.println( response.readEntity( String.class ) );
    }

    client.close();
}

Response:

Status: 201 (PUT was successful)

Parent topic:Update Scan