Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..
676 views

add attachment during Incident Creation - REST API

We are trying to integrate between ThirdParty system and HP SM, doing this all through REST API where a Request body is sent from third party to create incident, interaction, requet which are working fine, now what we are trying to do is send over an attachment (e.g. a text file) along with the incident creation message, this attachment is on ThirdParty system. How do I bring the attacmhents along with other while creating tiicket  in HPSM through Rest api? Any help would be very much appreciated!

 
Labels (2)
0 Likes
12 Replies
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Anyone Guys?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

I have done this in SOAP UI as follows

 

Method

POST

Endpoint

https://server.domain:13081 (port used for connection)

Resource

/SM/9/rest/incidents/<Incident ID Number>/attachments

 

Then set json media type to for example

{

   "attachments" : [

   {

      "attachment" : {

         "name" : "seantest.log"

      }

   }]

}

add headers

Content-Dispostion

attachment; filename=seantest.log

Content-Type

application/octet-stream

 

Add the attachment to the rest call on the attachment tab and run the POST to SM

 

 

Highlighted
Micro Focus Expert
Micro Focus Expert

Hi,

The REST interface works on a resource or a resource collection. You specify on with in the URL of the request.

The SM REST interface handles attachments of an incident as a resource collection.

The service document shows following resources:

Incident

Resource type Supported Methods URI
Resource Collection GET/POST http://localhost:13080/SM/9/rest/incidents
Single Resource GET/POST/PUT http://localhost:13080/SM/9/rest/incidents/{number}
Resource Attachment Collection GET/POST/DELETE http://localhost:13080/SM/9/rest/incidents/{number}/attachments
Resource Single Attachment GET/PUT/DELETE http://localhost:13080/SM/9/rest/incidents/{number}/attachments/{id}

Supported actions:

Action name Supported Methods URI
Create POST http://localhost:13080/SM/9/rest/incidents/{number}/action/create
Close POST http://localhost:13080/SM/9/rest/incidents/{number}/action/close
Update POST http://localhost:13080/SM/9/rest/incidents/{number}/action/update
Resolve POST http://localhost:13080/SM/9/rest/incidents/{number}/action/resolve

 

I understand this design, that in a single REST request, you can either update the incident record or add/update/delete attachments to an existing incident - but not both at the same time.

The small tests I did on this quickly with SOAP UI also verified this.

 

So the way to do this:

1. Create the incident by REST POST request

http://localhost:13080/SM/9/rest/incidents/{dummy number}/action/create

2. Extract the incident number of the response

3. Add an attachments to the incident by REST POST request

http://localhost:13080/SM/9/rest/incidents/{number}/attachments

 

I hope this helps.

Armin

Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hey thanks for the prompt response Franke.

Well, that was the thing which i had planned for, but wanted to check if there is any feasibility of doing it in single request.

Could you please let me know if we can attach more than one attachment by using the below

http://localhost:13080/SM/9/rest/incidents/{number}/attachments

I tried testing it in SOAP UI, by adding two attachments in the attachment tab and with the following header

Header: Content-Disposition

Value: attachment;filename=LICENSE.txt;filename=soapui.log

Only the first filename (LICENSE.Txt) is getting attached to incident, but not second attachment.

Do you have any thoughts? Thanks for the assisting us.

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hey thanks for the prompt response .

Could you please let me know if we can attach more than one attachment by using the below

http://localhost:13080/SM/9/rest/incidents/{number}/attachments

I tried testing it in SOAP UI, by adding two attachments in the attachment tab and with the following header

Header: Content-Disposition

Value: attachment;filename=LICENSE.txt;filename=soapui.log

Only the first filename (LICENSE.Txt) is getting attached to incident, but not second attachment.

Do you have any thoughts? Thanks for assisting us.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

I think it is only possible to attach one file by a REST request.

My results actually are of my own tests with the information about the RESTful design as available in documentation and the service document. So there may be still something I have not understood.

In my tests, I could only generate a single part message to attach a single file.

When I tried multi part, then the part also has a header that included Content-Disposition.

It would have been a clean approach to set the part header to the file name of the file in the part.

However, I didn't get this to work: SM only inspects the Content-Disposition in the main header - and there you cannot add multiple file names.

 

In my perspective, it would be a great idea that SM should handle multi-part REST requests to attach multiple files. If you log this to Idea Exchange, I'll vote for it.

In the meantime however, we have either to use a webservice requests to attach multiple files - respective one REST request per file.

Best regards,

Armin

Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hi Armin,

Thanks for the reply. 

Need your help here, third party are trying to consume our REST API to insert attachment, attachments are there in binary format in their system, in this case.

- What attributes has to passed for the attachment body in the REST request?

- And what are the supported attachment format ?

Could you please help me out here.

Regards,

Madhu

0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hi Sean,

Third party are trying to consume our REST api to insert attachment, attachments are there in binary format in their system, in this case.

- What attributes has to passed for the attachment body in the REST request?

- What are the supported attachment format ?

 

Could you please help me out here.

Regards,

Madhu

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Hi Madhu,

Please set the Content-Disposition to start with "attachment" (it the contains file name etc). Per REST request, you can only POST or PUT one attachment - not multiple in a multi-part HTTP request.

The it actually should work.

You say the file is available in "binary format" - well, that is actually what the POST body should contain.

If the source contains something like BASE64 encoded - well that is not supported by SM directly. SM has JS global functions to do such a conversion - so it might be possible to do such a conversion in extaccess record. But I have not tested this.

I would suggest to do some tests with 3rd-party tools like Postman. Postman runs in browser - and so you can use browser network trace to inspect the details of the request sent.

Best regards,

Armin

Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hi Armin,

Currently, we are able to post files from CRM to ITSM in file format (tested on Postman), but in CRM file is stored in base64 format, if we are posting the same base64 format from CRM to ITSM, it is not getting converted into files rather it just attaching base64 format data as an attachment in ITSM.
 
Could you pls guide as how to handle the attachments coming to same in base64 format.
 
Regards,
Madhu
0 Likes
Highlighted
Valued Contributor.. Valued Contributor..
Valued Contributor..

Hi Armin,

I did pass the base64 format in SOAP UI for WSDL , it worked, without any decoding from SM side, but I need this to work for REST API, any thoughts on which field/attribute do I have to pass base64 in REST API?

 

 <ns:attachments>
<!--Zero or more repetitions:-->
<com:attachment xm:contentType="application/" href="" contentId="" action="add" name="catalina.2019-12-18.log" type="" len="" charset="" attachmentType="">RGVjIDE4LCAyMDE5IDI6Mzk6MjEgUE0gb3JnLmFwYWNoZS5jYXRhbGluYS5jb3JlLkFwckxpZmVjeWNsZUxpc3RlbmVyIGluaXQNCklORk86IFRoZSBBUFIgYNzk0OCBtcw0K</com:attachment>
</ns:attachments> 

 

Regards,

Madhu

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.