Frequent Contributor.
Frequent Contributor.

SOAP Request for Add Attachment to existing incident

I am trying to add an attachment for existing incident via SOAP request. 

I tried this,

import requests
import json
import re
import sys
import xml.etree.ElementTree as ET
from pprint import pprint
import sys
import xml.dom.minidom as minidom
class Add_Attachment(Action):
headers = {'Content-Type' : 'text/xml', 'SOAPAction': 'Update'}
body = '<?xml version = "1.0" encoding = "UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime"><soapenv:Header/><soapenv:Body><ns:UpdateIncidentRequest attachmentInfo="true" attachmentData="true" ignoreEmptyElements="true"><ns:model query=""><ns:keys><ns:IncidentID type="String" mandatory="" readonly="">'+TICKET_NUMBER+'</ns:IncidentID></ns:keys><ns:instance query="" uniquequery="" recordid="" updatecounter=""><JournalUpdates><JournalUpdates>Attachment done by HiveCenter</JournalUpdates></JournalUpdates><ns:attachments><com:attachment name="sample.txt" action="add" href="cid:/tmp/text1.txt"></com:attachment></ns:attachments></ns:instance></ns:model></ns:UpdateIncidentRequest></soapenv:Body></soapenv:Envelope>'
response = requests.post(url,data=body,headers=headers,auth=(USERNAME, PASSWORD))

It is adding the attachment with the given name(simple.txt) but content is not decoded properly. I tried to take the file from linux server. i am not sure how to pass the file path/file content exactly. Please help us on this.


2 Replies
Honored Contributor.
Honored Contributor.

Re: SOAP Request for Add Attachment to existing incident

Hello Geetha

did you come up with this by yourself or by following a guide? 

Here is an official document on Web Services, please refer to the attachment seccion 

Sample script to send a record with attachments within
Service Manager


Hope this helps.


If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the STAR at the bottom left of the post and show your appreciation.
Frequent Contributor.
Frequent Contributor.

Re: SOAP Request for Add Attachment to existing incident

Thank you for the quick reply. 

I have followed the below links,




I tried with all the options posted in forumns. I am not sure how to pass the file which is present in linux server.If i give filepath directly inside attachment tag instead of href tag like below, it is working but file content is encoded to some format instead of original plain text.

<ns:attachments><com:attachment name="sample.txt" action="add" href="">/tmp/sample.txt</com:attachment></ns:attachments>

Please post the sample if you have for UpdateIncidentRequest.



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.