すべての REST 呼び出しにわたる HTTP セッションの永続化Issue REST API RestMessage を使用している場合、ループで複数の REST 呼び出しを実行すると、元のセッションは使用されず、複数のセッションが作成されるため、認証エラーが発生する可能性があります。 ]stats.do を表示すると、スクリプト化されたREST APIを実行した後に作成されている多くのセッションのリストが表示される場合があります。同じセッションを使用することが想定されている後続の REST 呼び出しで 401 または 429 エラーが発生します。Causeセッション Cookie の形式が正しくありません。Resolutionセッションの再利用は、Cookieを使用することで可能です。Cookie は SET-COOKIE ヘッダーで送信され、getCookies() を使用して取得できます。方式。 Cookieを機能させるには、適切にフォーマットする必要があります。例: 応答から返される実際の Cookie の例: [JSESSIONID=BDE538E6F87C4FA2DFFA0DA9F6E4E14F;Secure; Path=/; HttpOnly, glide_user="";Secure; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly, glide_user_session="";Secure; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly, glide_user_route=glide.9c5c58ba0c5169641af04031a4b26990;Secure; Expires=Wed, 02-Jan-2086 22:48:02 GMT; Path=/; HttpOnly, glide_session_store=41E2F0FDDBC38300E814FA56BF961953;Secure; Expires=Fri, 15-Dec-2017 20:03:55 GMT; Path=/; HttpOnly, BIGipServerpool_myinstancename=427827210.48704.0000; path=/]後続の呼び出しで送信するためにフォーマットされた後のCookieの例:JSESSIONID=BDE538E6F87C4FA2DFFA0DA9F6E4E14F;glide_user_route=glide.9c5c58ba0c5169641af04031a4b26990;glide_session_store=41E2F0FDDBC38300E814FA56BF961953;BIGipServerpool_myinstancename=427827210.48704.0000 次のコードは、Cookie 文字列を適切に書式設定して格納し、最初の要求に続く後続の REST 呼び出しで送信するために使用されました。 var getCallRequest= new sn_ws.RESTMessageV2(); getCallRequest.setEndpoint('https://<instanceName>.service-now.com/api/now/table/incident/<int_sys_id>'); getCallRequest.setBasicAuth('username','password'); getCallRequest.setHttpMethod("get"); getCallRequest.setRequestHeader("Accept", "application/json"); //execute print response info: var getCallResponse = getCallRequest.execute(); gs.print("status code: " + getCallResponse.getStatusCode()); gs.print("body: " + getCallResponse.getBody()); //print cookie info var cookies = getCallResponse.getCookies(); gs.log("cookies>>>>" + cookies); //extract cookies from response var jsessionid = ""; var glide_user_route = ""; var glide_session_store = ""; var BIGipServerpool = ""; var cookiesArray = (''+cookies).split(';'); //iterate through all cookies, found interesing ones for ( var i = 0; i < cookiesArray.length; i++) { if( cookiesArray[i].indexOf("JSESSIONID") > -1) { jsessionid = cookiesArray[i].substring( cookiesArray[i].indexOf("JSESSIONID"),cookiesArray[i].length); } if( cookiesArray[i].indexOf("glide_user_route") > -1) { glide_user_route = cookiesArray[i].substring( cookiesArray[i].indexOf("glide_user_route"),cookiesArray[i].length); } if( cookiesArray[i].indexOf("glide_session_store") > -1) { glide_session_store = cookiesArray[i].substring( cookiesArray[i].indexOf("glide_session_store"), cookiesArray[i].length); } if( cookiesArray[i].indexOf("BIGipServerpool") > -1 ) { BIGipServerpool = cookiesArray[i].substring( cookiesArray[i].indexOf("BIGipServerpool"), cookiesArray[i].length); } } //use same cookies in the next 50 calls var cookieValueStr = jsessionid + ";" + glide_user_route + ";" + glide_session_store + ";" + BIGipServerpool; gs.log(">>>>> cookieValueStr="+cookieValueStr); for (i = 0; i < 50; i++) { //getCallRequest.setCookie(cookies); //setCookie not documented getCallRequest.setRequestHeader("Cookie",cookieValueStr); var putCallResponse = getCallRequest.execute(); gs.log(putCallResponse.getBody()); }