GMO Sign: Retrieve Timestamped File URL

GMO Sign: Retrieve Timestamped File URL

GMO サイン: タイムスタンプ付与済ファイルURL取得

This item retrive timestamp request status and timestamped PDF file URL from GMO Sign.

Auto Step icon
Configs for this Auto Step
conf_OAuth2
C1: Secret Key *
cusId
C2: Customer id *#{EL}
accessUrl
C3: Access url *#{EL}
confirmationId
C4: Confirmation Id *
status
C5: Timestamp request status *
documentsUrl
C6: Timestamped File(Document) download URL *
Script (click to open)


/*
JSON例


・アクセストークン生成 AccessToken_Generate_Post
{
  "secret_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cus_id": "XXXXXXXXXX"
}

・タイムスタンプ付与済PDF取得 Timestamp_Retrieve_Post
{
  "secret_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cus_id": "XXXXXXXXXX",
  "access_token": "(取得したトークン)",
  "confirmation_id": "(取得した予約ID)",
  "download_type": "2"
}

・タイムスタンプstatus一覧
accepted: 処理待ち
applied: タイムスタンプ付与完了
declined: タイムスタンプ付与失敗
*/


main();

function main() {

    //// == 工程コンフィグの参照 / Config Retrieving ==
    //シークレットキーはHTTP認証設定のトークン直接指定に入れてもらう
    const key = configs.getObject("conf_OAuth2").getToken() + "";
    const cusId = configs.get("cusId") + "";
    const accessUrl = configs.get("accessUrl") + "";

    const dataId_status = configs.get("status");
    const dataId_documentsUrl = configs.get("documentsUrl");

    //// == ワークフローデータの参照 / Data Retrieving ==
    const confirmationId = engine.findData(configs.getObject("confirmationId")) + "";


    //// == 演算 / Calculating ==

    //アクセストークン取得
    let accessToken = getAccessToken(key, cusId, accessUrl);

    //ステータス・ファイルURL取得
    let json = retrieveTimestampedFileURL(key, cusId, accessUrl, accessToken, confirmationId);

    //// == ワークフローデータへの代入 / Data Updating ==
    engine.setDataByNumber( dataId_status, json['result']['status'] );
    engine.setDataByNumber( dataId_documentsUrl, json['result']['documents_url'] );


/* アクセスログがあれば
    if ( dataId_log !== "" ) {
        engine.setDataByNumber( dataId_log, accessLog );
    }
*/

}


/**
  * アクセストークン取得
  * @param {String} key  シークレットキー
  * @param {String} cusId  顧客ID
  * @param {String} accessUrl  接続先URL
  * @returns {String} アクセストークン
  */
function getAccessToken(key, cusId, accessUrl) {

    //JSON準備
    let requestObj = {};
    requestObj.secret_key = key;
    requestObj.cus_id = cusId;
    requestObj.download_type = 2;


    //HTTPリクエスト送付
    const url = "https://" + accessUrl + "/agree-api/v0/api/accesstoken/generate";
    const response = httpClient.begin()
        .body( JSON.stringify(requestObj), "application/json" )
        .post(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw `Failed to get access token. status: ${status}`;
    }

    engine.log("responseStr:" + responseStr);//検証用
    const json = JSON.parse(responseStr);
    return json['result']['access_token'];
}


/**
  * タイムスタンプ付与済ファイルURL取得
  * @param {String} key  シークレットキー
  * @param {String} cusId  顧客ID
  * @param {String} accessUrl  接続先URL
  * @param {String} accessToken  アクセストークン
  * @param {object} files  ファイル
  * @returns {String} レスポンスJSON
  */
function retrieveTimestampedFileURL(key, cusId, accessUrl, accessToken, confirmationId) {

    //JSON準備
    let requestObj = {};
    requestObj.secret_key = key;
    requestObj.cus_id = cusId;
    requestObj.access_token = accessToken;
    requestObj.confirmation_id = confirmationId;
    requestObj.download_type = 2;

    engine.log("requestObj:" + JSON.stringify(requestObj));//検証用


    //HTTPリクエスト送付
    const url = "https://" + accessUrl + "/agree-api/v0/api/ts/retrieve";
    const response = httpClient.begin()
        .body( JSON.stringify(requestObj), "application/json" )
        .post(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw `Failed to retrieve. status: ${status}`;
    }

    engine.log("responseStr:" + responseStr);//検証用
    const json = JSON.parse(responseStr);
    return json;//複数項目取得したいのでjsonのまま返す
}

  
    

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • GMO Sign is a service provided by GMO GlobalSign Holdings, Inc.
  • GMO Sign’s time stamping is included in the Scan Document Management function, which is included in the Security and Internal Control Pack (Information current as of 2024-07-25. The configuration may change, so please check with the provider.)
  • To add a timestamp using GMO Sign, you need to use a combination of GMO Sign: Request for Timestamp and GMO Sign: Retrieve Timestamped File URL.
  • For “Secret Key”, “Customer ID”, and “Access URL”, please specify the values ​​provided by GMO GlobalSign Holdings, Inc. For “Secret Key”, please specify “Direct token specification” in “HTTP authentication settings”.
  • For “Timestamp request status”, please prepare and specify a Select-type data item using the following settings.
  • Choices IDDisplay Label
    acceptedPending
    appliedTime stamp added
    declinedTimestamp assignment failure

    Capture

    See Also

    Scroll to Top

    Discover more from Questetra Support

    Subscribe now to keep reading and get access to the full archive.

    Continue reading