SaveResponseBodyAsAttachment() method failing with Unable to save response body as attachment: User not authorized .

rahulyamgar
Tera Guru

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

1 ACCEPTED SOLUTION

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

View solution in original post

13 REPLIES 13

Hi Rahul,

Is that user having valid role to add attachment to data source?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Do i need to check access to attachment table ?

Hi Rahul,

for adding attachment to data source table user should have import_admin role and user with that role can run transform map

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Marc4
Tera Expert

Hi, I have exactly the same problem and I’m admin. How can I fix this?

In our case, the API returns an application/pdf in the attachment of the http response.

I'm on New York.

thanks

Marc

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