- Print
- PDF
cancelJob
- Print
- PDF
Available in Classic and VPC
Cancel a diagnostic registered by a user in the NAVER Cloud Platform console before it starts.
Request
The following describes the request format for the endpoint. The request format is as follows:
Method | URI |
---|---|
PATCH | /{instanceId}/cancel |
Request headers
For headers common to Web Security Checker, see Web Security Checker common request headers.
Request path parameters
The following describes the parameters.
Field | Type | Required | Description |
---|---|---|---|
InstanceId | Integer | Required | Diagnostic identification number
|
Request example
The following is a sample request.
curl --location --request PATCH 'https://wsc.apigw.ntruss.com/api/v1/jobs/{instanceId}/cancel'
--header 'x-ncp-apigw-timestamp: {Timestamp}'
--header 'x-ncp-iam-access-key: {Access Key}'
--header 'x-ncp-apigw-signature-v2: {API Gateway Signature}'
--header 'Content-Type: application/json'
Response
The following describes the response format.
Response status codes
For error codes common to Web Security Checker APIs, see Common Web Security Checker error codes.
Response example
The following is a sample example.
- Diagnostic job canceled
{
"returnCode": "0",
"returnDesc": "Request Success",
"returnMessage": "Success",
"resources": null
}
- Diagnostic job cancellation error: Invalid
InstanceId
entered
{
"error": {
"errorCode": 901,
"message": "API Call Fail"
}
}
Sample code
To cancel a diagnostic, you need the Search diagnostics API and the Cancel diagnostics API. You need to extract the value of instanceNo
of the diagnostic you want to cancel the job from among the diagnostics that are in the Pending status via the Search diagnostics API and use this value to call the Cancel diagnostics API.
See getJobs or searchJobs for more information on how to search for diagnostics and check instanceNo
, as well as sample code for those APIs.
Sample code from a search with the Search diagnostics API (searchJobs) is as follows.
- Search type:
url
- Keyword:
target-domain.com
# Request example
$ python jobSearch.py "url target-domain.com"
# Response example
{
"returnCode": "0",
"returnDesc": "Request Success",
"returnMessage": "Success",
"resources": {
"total_cnt": 1,
"total_page_cnt": 1,
"current_start_page": 1,
"current_end_page": 1,
"record_data": [
{
"instanceNo": "1234567890",
"start_date": "2024-07-31 00:00:00",
"end_date": "",
"status": "Scheduled",
"progress": null,
"start_url": "http://target-domain.com",
"crawl_cnt": "",
"scan_cnt": "",
"memo": "Wsc Sample",
"result_button": "cancel",
"result_desc": "",
"rescan_button": "",
"slave_data": null
}
]
}
}
The following is sample code that generates a signature with the make_signature function to create a request head and then cancel it before diagnosing based on the request parameters entered, outputting the result if the response code is 200.
import sys
import os
import hashlib
import hmac
import base64
import requests
import time
import json
from pprint import pprint
def make_signature(method, uri, timestamp):
access_key = "{accessKey}" # access key id (from portal or sub account)
secret_key = "{secretKey}" # secret key (from portal or sub account)
secret_key = bytes(secret_key, 'UTF-8')
method = method
uri = uri
message = method + " " + uri + "\n" + timestamp + "\n" + access_key
message = bytes(message, 'UTF-8')
signingKey = base64.b64encode(hmac.new(secret_key, message, digestmod=hashlib.sha256).digest())
return signingKey
method = 'PATCH'
instanceId = "{instanceId}" # instance id (from api)
uri = f'/api/v1/jobs/{instanceId}/cancel'
timestamp = str(int(time.time() * 1000))
signature = make_signature(method, uri, timestamp)
headers = {
'x-ncp-apigw-signature-v2': signature.decode('utf-8'),
'x-ncp-apigw-timestamp': timestamp,
'x-ncp-iam-access-key': '{accessKey}', # access key id (from portal or sub account)
'Content-Type': 'application/json'
}
response = requests.request(
method,
f"https://wsc.apigw.ntruss.com{uri}",
headers=headers
)
if response.status_code == 200:
pprint(json.loads(response.text))
else:
pprint(json.loads(response.text))
The sample code is written in Python 3. See Call API in the API Gateway user guide for sample code written in other languages, such as Java and Node.js.