MENU
      cancelJob

        cancelJob


        記事の要約

        Classic/VPC環境で利用できます。

        NAVERクラウドプラットフォームコンソールでユーザーが登録した診断を開始する前にキャンセルします。

        リクエスト

        リクエスト形式を説明します。リクエスト形式は次の通りです。

        メソッドURI
        PATCH/{instanceId}/cancel

        リクエストヘッダ

        Web Security Checkerで共通して使用されるヘッダの詳細は、Web Security Checkerのリクエストヘッダをご参照ください。

        リクエストパスパラメータ

        パラメータの説明は次の通りです。

        フィールドタイプ必須の有無説明
        InstanceIdIntegerRequired診断の識別番号

        リクエスト例

        リクエストのサンプルコードは次の通りです。

        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'
        Curl

        レスポンス

        レスポンス形式を説明します。

        レスポンスステータスコード

        Web Security Checker APIで共通して使用されるエラーコードの詳細は、Web Security Checkerの共通エラーコードをご参照ください。

        レスポンス例

        レスポンスのサンプルコードは次の通りです。

        • 診断ジョブキャンセル完了
        {
            "returnCode": "0",
            "returnDesc": "Request Success",
            "returnMessage": "Success",
            "resources": null
        }
        JSON
        • 診断ジョブキャンセルエラー: 無効なInstanceIdを入力した場合
        {
            "error": {
                "errorCode": 901,
                "message": "API Call Fail"
            }
        }
        JSON

        サンプルコード

        診断をキャンセルするには、診断検索 APIと診断キャンセル APIが必要です。診断検索 APIを通じて予約(Pending)状態の診断の中からジョブをキャンセルする診断のinstanceNo値を抽出し、この値を利用してキャンセル APIを呼び出します。
        診断の検索とinstanceNoの確認方法、その APIのサンプルコードの詳細は、getJobsまたはsearchJobsをご参照ください。

        診断検索 API(searchJobs)で検索したサンプルコードは次の通りです。

        • 検索タイプ: url
        • キーワード: target-domain.com
        # リクエスト例
        $ python jobSearch.py "url target-domain.com"
        
        # レスポンス例
        {
            "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": "予約",
                        "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
                    }
                ]
            }
        }
        Bash

        make_signature関数でシグネチャーを作成してリクエストヘッドを作成し、入力したリクエストパラメータに応じて診断する前にキャンセルしてレスポンスコードが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))
        Python
        参考

        サンプルコードは Python3を基に作成しました。Java、Node.jsなど他の言語で作成したサンプルコードは、API Gatewayご利用ガイドのAPIの呼び出しをご参照ください。


        この記事は役に立ちましたか?

        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.