Outbound REST through MID Server - saveResponseBodyAsAttachment error

matt_kean
Tera Guru

Any help?  I am doing an outbound REST call through my MID Server to get user pictures. I can verify that I get a successful response until I add a saveResponseBodyAsAttachment statement to my script.  With that statement I always get the following error:

-  java.net.SocketTimeoutException: connect timed out when posting to https://xxx.service-now.com/api/now/v1/attachment/file

Here is my script (with private data removed) -

 

var user = new GlideRecord('sys_user');

user.addQuery('xxx','xxxxxxxx');

user.query();

if(user.next()) {

try {  

var token = '';

var s = new sn_ws.SOAPMessageV2('xxxxx', 'xxxxx');

s.setStringParameterNoEscape('userId', 'xxxxx');

s.setStringParameterNoEscape('credential', 'xxxxxx');

var responseS = s.execute();

var responseBodyS = responseS.getBody();

var xmlDoc = new XMLDocument(responseBodyS.toString(), true);

var token = xmlDoc.getNodeText("//authenticateReturn");

 

var r = new sn_ws.RESTMessageV2('User Photos', 'Get User Picture');

r.setStringParameterNoEscape('cookie', 'xxxxxx' + token);

r.setStringParameterNoEscape('xxxx', user.xxx.toString());

r.saveResponseBodyAsAttachment('ZZ_YYsys_user', user.sys_id.toString(), 'photo', 'image/jpeg');

var response = r.execute();

gs.print(response.getStatusCode());

gs.print(response.getErrorMessage());

}

catch(ex) {

gs.print('Got an exception:  ' + ex.getMessage());

}

}

1 ACCEPTED SOLUTION

matt_kean
Tera Guru

After a lot of testing, an incident with ServiceNow, and a wireshark I found the issue.   My outbound REST call uses a MID Server to get to our internal picture server. Our MID server has to use a proxy to get from the MID to our instance.   What I've found is that the saveResponseBodyAsAttachment() method is attempting to go straight from the MID server to our instance. It is not using the MID server's defined proxy.  



Unfortunately, there isn't a way for me to add an option or configure it to use the proxy.   I've asked for a problem ticket or enhancement request from ServiceNow to have saveResponseBodyAsAttachment() use a defined proxy when a MID server is used.


View solution in original post

15 REPLIES 15

davidpiper
ServiceNow Employee
ServiceNow Employee

This was also reported to Customer Support, and the following problem is fixed from the London release:

PRB1028554 Rest Message .saveResponseBodyAsAttachment function  does not work when proxy is involved