- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 07:05 AM
Hi
I am in middle of posting an attachment( lets says an image of jpeg format) with Rest Attachment API. I am confused about the raw data to be used in the request,
I have been trying it with Rest API Explorer and unable to find what is supposed to be added in raw data.
I don't want to upload a file directly through Binary data option as I am getting the data in base64 format from a 3rd party.
PS: I also don't want to use ECC-queue function to add an attachment.
Any light on it is highly appreciated.
Thanks
Gaurav
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 02:42 AM
Hi Andrew
I got it working as I was calling the table API and not attachment API here.
Took reference from the below link.
https://community.servicenow.com/thread/266337#1153136
Thanks for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 07:20 AM
Hi Andrew,
I want to achieve it through ServiceNow itself.
I have an image with me which I am trying to post it to another SNOW instance, I can't upload an image as I want to do it programmatically.
I was able to achieve it with Attachment Creator with ECC QUEUE method. Here I am looking for an alternative of achieving the same with attachment API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 07:26 AM
Ah ok,
Try the setRequestBodyFromAttachment function of RESTMessageV2:
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_RMV2-setReqBodyFromAttachment_S
This should allow you to send an attachment straight to the Attachment API.
Andy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 01:24 AM
Thanks Andrew for guiding me through.
Now, I am trying to create a ticket from one instance to another with an attachment as well.
But the receiving instance is not taking the request body now and throwing error while reading the request.
My doubt is that the request body is not properly typecast into string/base64.
Info Message {"error":{"detail":"Cannod decode: java.io.StringReader@102d59","message":"Exception while reading request"},"status":"failure"}
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://example.service-now.com/api/now/table/incident?sysparm_fields=number');
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody("{\"short_description\":\"This is test ticket created from rest message API\",\"description\":\"This is test ticket created from rest message API\"}");
//get attcahment sysyId
var atttchSysId = getAttcahmentId(current);
gs.addInfoMessage(atttchSysId);
if(atttchSysId!=''){
request.setRequestBodyFromAttachment(atttchSysId);
}
gs.addInfoMessage("request body is "+request.getRequestBody());
var response = request.execute();
gs.addInfoMessage(response.getBody());
})(current, previous);
function getAttcahmentId(currentObj){
var gr = new GlideRecord('sys_attachment');
gr.get('table_sys_id',currentObj.sys_id);
return gr.sys_id.toString();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2017 02:42 AM
Hi Andrew
I got it working as I was calling the table API and not attachment API here.
Took reference from the below link.
https://community.servicenow.com/thread/266337#1153136
Thanks for your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-29-2017 07:19 AM
Hi Gaurav,
you want to check the functinality works in Rest Api explorer
if you want to integrate with third party
Please provide your feedback appropriately (Like, Helpful, Endorse AND/OR Correct) to help community.
Thanks
Chandu Telu