Need to create the scripted rest api to capture Attachment

balaji_prusty1
Giga Guru

Hi All,

 

I have created a scripted API through which third-party tool creates an incident in my instance using json. Now they are sending attachments with the JSON. I need to attach the attachment in my incident. 

 

Here the below sample Json which I received from the third party tool. In this json, it is not showing the file type,name etc. Only timestamp and attachment_id. Not sure how to configure to capture the attachment. Can someone please help on this. 

 

{

"Number" : "CS0134435",

"Short_description" : "Test Short Description",

"Description" : "Test Description",

"Priority" : "Low",
"Closed" : "",
"Closed_notes" : "",
"Comments" : "",
"Attachments" : [ {
"Timestamp" : "2024-05-13T12:42:13.000Z",
"Attachment_id" : "f2707b0a4e10eaf4ec6fe54bcb5d"
} ]

}

4 REPLIES 4

balaji_prusty1
Giga Guru

 

@Ankur Bawiskar Can you please help on my query. 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@balaji_prusty1 

what information are they sending for attachment?

you should get file name, file type, base64 data of that file. then only you can create file

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

Hi Ankur,

 

Thanks for the quick response. As I mentioned above, I am getting this below JSON when third-party applications consume the Scripted REST API. The attachment parameter only has a timestamp and attachment_id.

 

{

"Number" : "CS0134435",

"Short_description" : "Test Short Description",

"Description" : "Test Description",

"Priority" : "Low",
"Closed" : "",
"Closed_notes" : "",
"Comments" : "",
"Attachments" : [ {
"Timestamp" : "2024-05-13T12:42:13.000Z",
"Attachment_id" : "f2707b0a4e10eaf4ec6fe54bcb5d"
} ]

}

Hi Ankur,

 

Third-party applications are sending the JOSN with the File name and File content. Can you please provide the generic cond to create an attachment for this JSON below?

 

{
"Filename" : "test_file.txt",
"File_content" : "mZdfdfdfsf1bCB3YXkgdG8gaGfgfVscCB5b3U"

}