Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
Absent Member.. abhin88 Absent Member..
Absent Member..
6108 views

RESTful API - Attachments for Incident

Hello Experts

 

I am quite new to RESTful. We have configured REStful for incidents, service requests and problem. I would like to know how I can add attachments for the same.

 

The current setup is 

 

1. There is an User portal from there incidents or service requests are created.

2. Users may want to attach these tickets which will be pushed to SM

3. The attachments should be available in Service Manager side as well.

 

Any help would be much appreciated.

 

Abhinav

 

Kindly assign kudos if the post is helpful!
Tags (1)
0 Likes
6 Replies
Absent Member.. lisajo Absent Member..
Absent Member..

Re: RESTful API - Attachments for Incident

Hi

Not sure if this will help or not but there is a discussion

 

http://h30499.www3.hp.com/t5/HP-Service-Manager-Service/Attachment-and-Webservice/td-p/5354705#.UyL0yoXLKjY

"HP Support
If you find that this post or any post resolves your issue, please make sure to mark it as an accepted solution."
0 Likes
Highlighted
MT03
New Member.

Re: RESTful API - Attachments for Incident

Hi,

 

yeah it's a good question - i spent some hours and found a solution.

 

I have tested with HPSM 9.33.0035 (WIN).

To simulate your external user portal, i have used soapUI in version 5.0.0.

 

My latest configuration is the following:

 

Method: POST

Endpoint: http://127.0.0.1:13080

Resource: /SM/9/rest/interactions/<your-interaction-id>/attachments

 

As Post Body, i have the following JSON Code (but i think, the post body is not required)

 

{
   "attachments" : [
   {
      "attachment" : {
         "name" : "soapui.log"
      }
   }]
}

 

 

I have attached an attachment in soapUI, named "soapui.log".

The Attachment is cached in my example.

The Content-Type of the attachment is "application/octet-stream".

 

Now the important part 🙂

 

You have to set a Header key named "Content-Dispostion".

The Value of this header is "attachment; filename=soapui.log"

 

The second Header key is "Content-Type".

The value of this header is "application/octet-stream" (without this, your attachment gets "application/json" as content-type.

 

Now, if you send your request to the HPSM, you should get the following response:

 

{
"Messages": [],
"ReturnCode": 0,
"attachment": {
"href": "cid:53467b610011401020594248",
"len": 85,
"name": "soapui.log",
"type": "application/octet-stream",
"xmime:contentType": "application/octet-stream"
}
}

 

 

Without the header (Content-Disposition) you will get something like this

 

{
"Messages": ["Attachment name is required."],
"ReturnCode": 71
}

 

 

I have attached some screenshots, which explains it in pictures 😉

 

 

Hope this helps.

 

 

Greets!

SN1 Contributor.
Contributor.

Re: RESTful API - Attachments for Incident

Hi,

I am trying to integrate SM - SNOW. Where i have written scripts for Open and update activities. Now i have started to code for attachments. Following is the code, i have used.

function sysattach(number,sysid)
{
print("Sending attachment");
var ahead = new Header("Accept","application/json, text/plain, image/jpeg, */*");
var cdhead = new Header("Content-Dispostion", "attachment; filename=tbl.filename");
var head=new Header("Content-type","application/octet-stream", "multipart/form-data, application/json, image/jpeg, text/plain, */*");
var req_header = new Header("Authorization", 'Basic YWRtaW46TmFnYXJqdW4kMQ==');
var header = new Array();
header.push(ahead);header.push(cdhead);header.push(req_header);header.push(head);

var f = new SCFile("probsummary")
var fqry = "number=\""+number+"\"";
var frc = f.doSelect(fqry);
var attachment = f.getAttachments();
for(var attachs in attachment)
{
print("Attachment Name:"+attachment[attachs].name);
print("Attachment value:"+attachment[attachs].stringValue);
print("Attachment calue length:"+attachment[attachs].stringValue.length);
print("Attachment type:"+attachment[attachs].type);
print("Attachment href:"+attachment[attachs].href);
var attchobj = f.getAttachment( attachment[ attachs ].href );
}
var attchfo = attchobj.value;
var encoded = base64Encode(attchfo);

var post_url="https://abcdef.service-now.com/api/now/attachment/file?table_name=incident&table_sys_id="+sysid+"&file_name="+attachment[attachs].name;
var body="";
body+="{";
//body+="\"payload\":\""+encoded+"\"";
body+="\"payload\":\""+attchfo+"\"";
body+="}";
//print("attachment body:"+body);
//print("inside sysattachment table");
try
{
var rcsys = doHTTPRequest("POST", post_url, header, body);
print(rcsys);
//print(ressys);
}
catch(e)
{
print(e)
}
return rcsys ;
}

The attachment is getting attached to IM in snow. But the content of the attachment is wrong. The content of the attachment is what i write in the body. not the actual attachment that is in hpsm

body+="{";
body+="\"payload\":\""+attchfo+"\"";
body+="}";

Can someone help me, where i am doing wrong.

Regards,

Nagarjun S

 

0 Likes
Kabelo Mabelane Contributor.
Contributor.

Re: RESTful API - Attachments for Incident

Bravo, well done.  it worked Thank you,

0 Likes
neelak
Established Member.

Re: RESTful API - Attachments for Incident

Hi,

 

Did you find the solution to this problem?

0 Likes
Regular Contributor.. Madhu1989 Regular Contributor..
Regular Contributor..

Re: RESTful API - Attachments for Incident

Hi, I am trying to create an incident through REST API, The incident is getting created with the request body that am passing, but attachment values are getting ignored and not getting inserted during the creation of the incident. Could you please assist as how to pass attachment in the json request body.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.