
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2024 08:47 AM
Hello everyone,
I'm working on integrating Plaid's /asset_report/pdf/get API with ServiceNow. My goal is to retrieve the PDF binary data(DONE) and attach it to a specific case record(PENDING; NEED_YOUR_HELP!!!).
I've written the following script to make the API call and attach the PDF:
var parsedResponse = '';
var httpStatus = '';
var responseBody = '';
try {
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://sandbox.plaid.com/asset_report/pdf/get');
request.setHttpMethod('POST');
request.setRequestHeader('Content-Type', 'application/json');
var requestBody = {
client_id: 'your_client_id_here',
secret: 'your_secret_here',
asset_report_token: 'your_report_token_here'
};
request.setRequestBody(JSON.stringify(requestBody));
var response = request.execute();
responseBody = response.getBody();
httpStatus = response.getStatusCode();
gs.info('HTTP Status: ' + httpStatus + '\n');
if (httpStatus === 200) {
var pdfFile = responseBody;
if (pdfFile) {
var sysId = 'case_record_sysID';
var tableName = 'table_name';
/*
// Code to process and attach the PDF to above case record
*/
gs.info("PDF has been successfully attached to the record.");
} else {
gs.error('Failed to attach PDF file to case.');
}
} else if (httpStatus == 400) {
gs.info("PS1: Asset PDF Report Not generated: " + responseBody);
}
} catch (ex) {
gs.error('Error occurred during API call: ' + ex.message);
}
However, I'm facing some issues:
- The PDF is not being attached to the record as expected. I have attached the response body, which contains the raw PDF data.
- I'm not sure if I'm correctly handling the binary data to create the attachment. Please see the attached sample asset report PDF—this is the result we're aiming to achieve.
If anyone has encountered similar issues or can spot what I might be missing, your insights would be greatly appreciated! Thank you so much in advance!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 01:29 PM - edited 08-13-2024 01:32 PM
Hello @Ankur Bawiskar ,
Thanks a ton for your help! Your guidance got me on the right track to creating a PDF and attaching it to a case record. However, I ran into a small hiccup—the file wasn’t handled correctly, and a blank PDF got attached.
Luckily, I stumbled upon a game-changer in the ServiceNow docs: the saveResponseBodyAsAttachment() method. This method automatically saves the response from an API call as an attachment to a specific record in ServiceNow. It makes saving files directly to records super easy after an API request.
For more details, check out the article I composed: Effortlessly Attach API Responses File to Record: Use saveResponseBodyAsAttachment()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2024 08:28 PM
@Community Alums
you can try this; convert binary to base64 and then use GlideSysAttachment to attach file
Attachments API - Converting Binary Files to Base64
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 01:29 PM - edited 08-13-2024 01:32 PM
Hello @Ankur Bawiskar ,
Thanks a ton for your help! Your guidance got me on the right track to creating a PDF and attaching it to a case record. However, I ran into a small hiccup—the file wasn’t handled correctly, and a blank PDF got attached.
Luckily, I stumbled upon a game-changer in the ServiceNow docs: the saveResponseBodyAsAttachment() method. This method automatically saves the response from an API call as an attachment to a specific record in ServiceNow. It makes saving files directly to records super easy after an API request.
For more details, check out the article I composed: Effortlessly Attach API Responses File to Record: Use saveResponseBodyAsAttachment()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 08:35 PM
@Community Alums
Glad to know.
Did you mistakenly marked your own response as correct?
If my response helped please mark my response as correct so that it helps others in future.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 10:08 PM
Hi @Ankur Bawiskar ,
Thank you for your assistance. I marked your response as helpful because it definitely guided me in the right direction, and I appreciate your input. However, I found a solution that specifically resolved my issue, so I accepted my own response as the Accept as Solution. This way, the community can have the correct solution for similar problems.
Thanks again for your support!