- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 09:31 AM
Hello Friends,
I am using the REST API call and saving the response body using the method - "saveResponseBodyAsAttachment(tablename, recordSysId, filename); ". I am setting the MID server to execute the request. Above method execution is failing with "Unable to save response body as attachment: User not authorized " error.
Please guide.
Thanks,
Rahul
Solved! Go to Solution.
- Labels:
-
MID Server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 08:25 AM
This is what we are doing:
1. Getting the ResponseBody.
var response = sm.execute();
var responseBody = response.getBody();
2. Creating an attachment using the below code, where gr is the GlideRecord to which file is attached.
attachment.write(gr,"SampleJson","json",responseBody);
It worked for me.
Thanks,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 09:26 AM
Hi, the solution does not work if the content-type of the response is application/pdf or application/octet-stream and in the documentation they do not recommend using getBody for large files.
I also try to return an application/json with the file in base64 and then use attachment.writeBase64. This works but the payload is almost twice the size.
Marc

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2020 07:56 AM
I ran into the same issue and I had to use saveResponseBodyAsAttachment as I was dealing with binary data; the problem is likely that the account the MID server is running under does not have sufficient rights to create in the target table (After trying custom ACLs on sys_attachment and sys_attachment_doc I found they were not the problem!)
In my case I was retrieving a file to use in a sys_data_source so the fix was simple, I just gave the MID server account the import_admin role which allowed it to write to the Data Source, likely you just need to give the MID server user the relevant permissions for your table_name that you are attaching to.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 11:43 AM
Hi, this solution does not work if the content-type of the response is application/pdf or application/octet-stream.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2020 11:43 AM
Hi, this solution does not work if the content-type of the response is application/pdf or application/octet-stream.