saveResponseBodyAsAttachment is not working

GD11
Tera Expert

I am using below code to save the outbound REST (GET) calls response to save in attachment table but it's not working, the code is not getting executed even if I comment out highlighted line of code. this returns response when we do not try to save the response, what am I missing? I followed - link

Note: Unable to use background script because it needs O-auth, non O- Auth link works in background script - Link

find_real_file.png

4 REPLIES 4

Maik Skoddow
Tera Patron
Tera Patron

Hi @Govind Dhande 

please do not call response.getBody() after execution of REST message. You can load the response as an attachment or fetch the response body as text, but not both!

For a working example please see https://developer.servicenow.com/blog.do?p=/post/saving-restmessagev2-responses-as-attachments/

Maik

Hello @Maik Skoddow  thanks for your input, I removed that but still the attachment is not getting stored into sys_attachment table. we are able to values in logs when we execute without saveresponsebodyasattachment. please advise. find_real_file.pnglogs:

find_real_file.png

Hi

there are tons of reason why it doesn't work for you and I really miss some debugging approaches from you. Neither I can read your thoughts nor I have access to your instance. Therefore, it is on you to provide ALL required information to help us understand your issue better,

For example:

  • In your REST Message object "RightAnswers article import" what happens if you open the URL configured at REST method "GET images". Can you see the image in your browser?
  • If yes: Did you increase the logging level for the REST message method "GET images" and did you check the respective records at table sys_outbound_http_log? Which status code is returned? Are there any meaningful log errors?

Maik

@Maik Skoddow  1. if we open the image in separate tab then we do see the image with it's absolute path which is from RightAnswers which we are accessing through reverse proxy, so no issue there.

2. I checked the HTTP outbound log table and I see that I am getting error that '[ERROR Code :200 ] unable to save response body as attachment: user not  authorized' though I have provided admin and knowledge admin role to the MID server user as we are trying to connect through MID server.

 

Thanks,
Govind