stopJob
    • PDF

    stopJob

    • PDF

    Article summary

    Available in Classic and VPC

    Stop a diagnostic registered by a user in the NAVER Cloud Platform console while it is in progress.

    Request

    The following describes the request format for the endpoint. The request format is as follows:

    MethodURI
    PATCH/{instanceId}/stop

    Request headers

    For headers common to Web Security Checker, see Web Security Checker common request headers.

    Request path parameters

    The following describes the parameters.

    FieldTypeRequiredDescription
    InstanceIdIntegerRequiredDiagnostic identification number

    Request example

    The following is a sample request.

    curl --location --request PATCH 'https://wsc.apigw.ntruss.com/api/v1/jobs/{instanceId}/stop'
    --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 stopped
    {
        "returnCode": "0",
        "returnDesc": "Request Success",
        "returnMessage": "Success",
        "resources": null
    }
    
    • Diagnostic stop job error: Invalid InstanceId entered
    {
        "error": {
            "errorCode": 901,
            "message": "API Call Fail"
        }
    }
    

    Sample code

    To stop a job while a diagnostic is in progress, you need the Search diagnostic API and the Stop diagnostic API. ou need to extract the value of instanceNo of the diagnostic in progress that you want to stop working on via the Search diagnostic API and use this value to request the Stop diagnostic 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 diagnostic API (jobSearch) 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-10 13:42:38",
                    "end_date": "",
                    "status": "Collecting URLs",
                    "progress": null,
                    "start_url": "http://target-domain.com",
                    "crawl_cnt": "",
                    "scan_cnt": "",
                    "memo": "",
                    "result_button": "terminate",
                    "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}/stop'
    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))
    
    Note

    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.


    Was this article helpful?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.