Scripted REST API - Get file binary data from multipart/form-data body

bryan_morvig
Tera Contributor

We have a need to develop a Scripted REST API resource that takes in attributes in query parameters and a path parameter, performs business logic including logging and identifying the record to attach a file to, and then use the GlideSysAttachment() API to attach the file.

The place where I am getting stuck is actually getting the Content-Type, fileName, and binary file payload OUT of the multipart/form-data body of the request.  All the research I have done points to using 3rd party libraries, which is a limitation in ServiceNow.  Are there any available libraries in ServiceNow that can be used to parse the multipart/form-data body or any other solution to get at that data?

Thanks!

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Bryan,

It seems ServiceNow won't understand the multi-part form data. So why not accept the base64encoded data of the attachment from 3rd party and then decode and add that as attachment to target record you wish.

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

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

Hello,


I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.


Could you please guide me how to implement this? Sample code would be great.


Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"Sys ID": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"Sys ID": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}

Shane-DXC
Tera Expert

Hey Bryan - did you find a solution to this issue?