Sending attachment through scripted rest API integration.

sr_surendra
Giga Expert

Dear all,

 

I have a requirement where I want incident to be created in servicenow where I'll be using inputs from source by using following.

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var data = request.body.data;
var category = data.category.toString();

Etc.

Etc................

 

As shown above to get data of source I'm using request.body.data - Here is my challange consider if source contains some attachments , I want those attachment to be attached to the incident that supposed to be created using this integration. What can I dot walk "request." to access information about attachments attached to the source data?

FYI

1)I can't use soap integration for this and I want to use REST only due to security concerns.

2)As a trial and error I tried "request.body.data.attachment" but I was failed to get attachment details.

Could someone please help me with this.

 

Thanks,

Surendra

 

1 ACCEPTED SOLUTION

Dubz
Mega Sage

Any particular reason why you're using a scripted REST API rather than just the normal table API? I don't know what your source system is but could you pass back the ID of the new incident you've created in the initial synchronous response and then use that to leverage the attachment API to send through the related attachments? 

https://developer.servicenow.com/app.do#!/rest_api_doc?v=madrid&id=c_TableAPI

I think that would be easier than figuring out how to script it but if you have to script it you'll probably find the GlideSysAttachment API useful.

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_SGSA-GlideSysAttachment

View solution in original post

3 REPLIES 3

Dubz
Mega Sage

Any particular reason why you're using a scripted REST API rather than just the normal table API? I don't know what your source system is but could you pass back the ID of the new incident you've created in the initial synchronous response and then use that to leverage the attachment API to send through the related attachments? 

https://developer.servicenow.com/app.do#!/rest_api_doc?v=madrid&id=c_TableAPI

I think that would be easier than figuring out how to script it but if you have to script it you'll probably find the GlideSysAttachment API useful.

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_SGSA-GlideSysAttachment

Hello David,

 

I have a requirement of integration with SAP .

As a solution we suggested them to use 2 APIs , one for incident creation, and one for attaching documents if any to incident created where we asked them to use attachment api.

 

But as per their requirement , they don't want to consume 2 APIs instead, they want one end point which can create as well as attach the documents . 

 

So I'm creating a scripted rest API. By using which it could perform activities of both creation and attachment of documents.

 

So, in order to get attachment sys_id, file type, etc attachment related information I wanted to know is there any way by which we can get those information from "response."

 

I hope you understood my question.

 

Regards,

Surendra

You'll have to confirm with whoever is generating the REST call where they are including the attachment data. Once you know where and how it is being sent you should be able to figure out how to parse it and attach it using the available API on ServiceNow.