Scoped Application Scripted REST API getCookies() returning null

mrgj
Mega Contributor

Good day raiders of the lost ark,

- I've created a Scripted REST API within a Scoped application (geneva developer instance).

- This API has 2 resources.

- Resource #1 calls Resource #2 and tries getCookies() with the response from #2.

  - In the logs i can see : NullPointerException ==> 27: var cookies = res.getCookies();

      and the response of Resource #1 is:

{
  "error": {
  "message": null,
  "detail": null
  },
  "status": "failure"
}

Resource #1 Code:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

        var restMessage = new sn_ws.RESTMessageV2();

        restMessage.setHttpMethod('get');

        restMessage.setEndpoint('https://INSTANCE.service-now.com/api/x_82127_sApp/myApi/cookieMonster');

        var resp = restMessage.execute();

        var cookies = resp.getCookies();

        var body = [];

        for(var i=0;i<cookies.size();i++) {

                  body.push(cookies.get(i));

        }

        response.setBody(body);

})(request, response);

Resource #2 Code:

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

        something = [

              {"id": 12034, "worked":"yes"},

              {"id": 1234, "worked":"yes"},

              {"id": 12, "worked":"no"}

        ];

        // implement resource here

        response.setBody(something);

})(request, response);

I have tried this example in Global scope and it works perfectly.

Therefore I'm guessing it's something to do with being a Scoped Application. I checked the scoped api and under "RESTResponseV2", getCookies() is there.

I've checked in the REST API Explorer and Resource #2 works fine and returns 200, Resource #1 returns 500 internal.

I've checked the setEndPoint and it's the correct endpoint (copy and pasted).

1 ACCEPTED SOLUTION

mrgj
Mega Contributor

For those who (if anyone) come across this issue, it's actually a problem and is currently being looked at by servicenow


View solution in original post

8 REPLIES 8

mrgj
Mega Contributor

#sorryfordoublepost



getheaders() and getBody() are working as usual. Just seems to be something to do with getCookies().


srinivasthelu
Tera Guru

setBasicAuth??


The two end points have basic authentication off. Thanks for input.


mrgj
Mega Contributor

For those who (if anyone) come across this issue, it's actually a problem and is currently being looked at by servicenow