Highlighted
Visitor.
6315 views

Curl command for HPSM webservices

Jump to solution

Hi Experts,

Kindly suggest how to use Curl command to call HP SM 9 and 7 webservices to create, update and retrive incidents. Please share the complete command with an example.

Thanks,

Akhil

0 Likes
1 Solution

Accepted Solutions
Highlighted
Visitor.

Hi 

 

 

View solution in original post

0 Likes
9 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Interesting, I created following curl commands to access HPE SM and I tested all of them on 9.41 with curl running on windows, all commands are based on the restful API:

1. get the incident list by curl :
curl -x "yourproxyserver:port" -XGET -H "Authorization: Basic base64usernamepassword" -H "Accept-Encoding: gzip,deflate" "http://yourSMurl:13080/SM/9/rest/incidents?Impact=3"

{
"@count": 2,
"@start": 1,
"@totalcount": 2,
"Messages": [],
"ResourceName": "Incident",
"ReturnCode": 0,
"content": [
{"Incident": {"IncidentID": "IM10001"}},
{"Incident": {"IncidentID": "IM10352"}}
]
}

2. update an incident by curl :
curl -x "yourproxyserver:port" -XPOST -H "Authorization: Basic base64usernamepassword" -H "Accept-Encoding: gzip,deflate" -H "Content-type: application/json" -d "{ 'Incident': { 'JournalUpdates': [ '08/04/08 12:54:14 US/Mountain (falcon):', 'test', '08/04/08 12:54:14 US/Mountain (falcon):', 'test' ], 'Urgency' : '4' } }" "http://yourSMurl:13080/SM/9/rest/incidents/IM10002"

response:

{
"Incident": {
"AlertStatus": "SLA BREACH",
...
},
"Messages": [
"Incident record updated.",
"Beijing 04/21/16 14:40:34: Incident IM10002 has been updated by lingyan"
],
"ReturnCode": 0
}

3. create a new incident by curl :
curl -x "yourproxyserver:port" -XPOST -H "Authorization: Basic base64usernamepassword" -H "Accept-Encoding: gzip,deflate" -H "Content-type: application/json" -d "{ 'Incident': { 'AlertStatus' : 'updated', 'Area' :'failure', 'Assignee' : 'Incident.Analyst', 'AssignmentGroup': 'Network', 'Category' : 'incident', 'ClosureCode' : 'Solved by Workaround', 'Company' : 'advantage', 'Contact' : 'FALCON, JENNIFER', 'ContactFirstName' :'FALCON', 'ContactLastName' : 'JENNIFER', 'Description' : [ 'test' ], 'Impact' : '2', 'JournalUpdates': [ '08/04/08 12:54:14 US/Mountain (falcon):', 'test', '08/04/08 12:54:14 US/Mountain (falcon):', 'test' ], 'Location':'advantage/North America', 'OpenTime' : '2007-09-02T07:51:00+00:00', 'OpenedBy':'Jurr.Fleijs', 'ProblemType' : 'incident', 'ResolutionFixType' : 'incident', 'SLAAgreementID' : 168, 'Service' : 'CI1001060', 'SiteCategory' : 'incident', 'Solution' : ['Solution by rest api'], 'Status' : 'Work In Progress', 'Subarea' :'function or feature not working', 'TicketOwner' : 'Jurr.Fleijs', 'Title' : 'test', 'UpdatedBy' : 'problem', 'UpdatedTime' : '2008-08-04T12:54:26+00:00', 'Urgency' : '3', 'UserPriority': '3 - Average', 'explanation' : ['test'], 'folder' :'advantage' } }" "http://yourSMurl:13080/SM/9/rest/incidents"

reponse:

{
"Incident": {
"AlertStatus": "updated",
...
"folder": "advantage"
},
"Messages": [
"Incident \"IM10426\" added.",
"Beijing 04/21/16 15:45:13: Incident IM10426 has been opened by lingyan"
],
"ReturnCode": 0
}

 

4. upload a text attachment named test.txt to an incident:

curl -x "yourproxyserver:port" -XPOST -H "Content-Type: text/plain" -H "Authorization: Basic base64usernamepassword" -H "Content-Disposition: attachment; filename=test.txt" -d "this is an text attachment" "http://yourSMurl:13080/SM/9/rest/incidents/IM10002/attachments"

response:

{
"Messages": [],
"ReturnCode": 0,
"attachment": {
"href": "cid:57187d75003d331180977df8",
"len": 26,
"name": "test.txt",
"type": "text/plain",
"xmime:contentType": "text/plain"
}
}

 I used several tools to generate these command:

1. SOAPUI which can test the restful request and http header if they works

2. then I convert the soapui request to the curl command by curl command builder at https://curlbuilder.com/

3. finally, I convert my username:password to base64 by using base64 encoder: http://www.motobit.com/util/base64-decoder-encoder.asp

4. if you can access your HPESM server without proxy, you can remove -x "yourproxyserver:port".

 

Hope it helps. 

Lingyan

Highlighted
Micro Focus Expert
Micro Focus Expert

You can also find more information about restful API at:

https://www.youtube.com/watch?v=-GGZo5KPlIo

0 Likes
Highlighted
Visitor.

Thanks Lingyanmeng for response.

 

In my case SM version is 7 so I will have to use webservice only. Please suggest, how can it be done for HP SM webservices as I think provided solution for Rest based URL.

 

Best Regards

Akhil

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Ok, as you put SM9 in front of SM7, I built those commands on SM9 which is restful API.

The command to consume SOAP is like below:


1. Get the incident list where impact=2 by curl SOAP:
curl -XPOST -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: "RetrieveKeysList"" -H "Authorization: Basic ZmFsY29uOjE=" -d "<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:RetrieveIncidentKeysListRequest ignoreEmptyElements='true'> <ns:model> <ns:keys> </ns:keys> <ns:instance> <Impact>2</Impact> </ns:instance> </ns:model> </ns:RetrieveIncidentKeysListRequest> </soapenv:Body> </soapenv:Envelope>" "http://localhost:13941/SM/7/"

response:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><RetrieveIncidentKeysListResponse message="Success" query="" returnCode="0" schemaRevisionDate="2014-12-07" schemaRevisionLevel="6" status="SUCCESS" xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.hp.com/SM/7 /Incident.xsd"><keys><IncidentID type="String">IM10004</IncidentID></keys><keys><IncidentID type="String">IM10036</IncidentID></keys><keys><IncidentID type="String">IM10060</IncidentID></keys><keys><IncidentID type="String">IM10205</IncidentID></keys><keys><IncidentID type="String">IM10206</IncidentID></keys></RetrieveIncidentKeysListResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

2. Get incident IM10002 detail curl SOAP:
curl -XPOST -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: "Retrieve"" -H "Authorization: Basic ZmFsY29uOjE=" -d "<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:RetrieveIncidentRequest attachmentData='false' attachmentInfo='false' ignoreEmptyElements='true'> <ns:model> <ns:keys query='number=&quot;IM10001&quot;'/> </ns:model> <ns:instance /> </ns:RetrieveIncidentRequest> </soapenv:Body> </soapenv:Envelope>" "http://localhost:13941/SM/7/"

response:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><RetrieveIncidentResponse message="Success" returnCode="0" schemaRevisionDate="2014-12-07" schemaRevisionLevel="6" status="SUCCESS" xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.hp.com/SM/7 /Incident.xsd"><model><keys><IncidentID type="String">IM10001</IncidentID></keys><instance recordid="IM10001 - Cannot add attachment to OneNote Shared directory." uniquequery="number=&quot;IM10001&quot;"><IncidentID type="String">IM10001</IncidentID><Category type="String">incident</Category><OpenTime type="DateTime">2013-12-30T03:02:55+00:00</OpenTime><OpenedBy type="String">falcon</OpenedBy><Urgency type="String">3</Urgency><UpdatedTime type="DateTime">2014-11-11T22:08:41+00:00</UpdatedTime><AssignmentGroup type="String">Application</AssignmentGroup><ClosedTime type="DateTime">2014-08-15T04:08:17+00:00</ClosedTime><ClosedBy type="String">Incident.Analyst</ClosedBy><ClosureCode type="String">Diagnosed Successfully</ClosureCode><Description type="Array"><Description type="String">Cannot add attachment to OneNote Shared directory.</Description></Description><Solution type="Array"><Solution type="String">Cleanup the backups in document server, free spaces.</Solution></Solution><Assignee type="String">Change.Analyst</Assignee><Contact type="String">CAFFREY, AARON</Contact><JournalUpdates type="Array"><JournalUpdates type="String">01/15/14 21:05:22 US/Mountain (Jennifer Falcon):</JournalUpdates><JournalUpdates type="String">Assign to Lopez</JournalUpdates></JournalUpdates><Company type="String">advantage</Company><Title type="String">Cannot add attachment to OneNote Shared directory.</Title><UpdatedBy type="String">falcon</UpdatedBy><Status type="String">Closed</Status><Phase type="String">Closure</Phase><Area type="String">failure</Area><Subarea type="String">function or feature not working</Subarea><Impact type="String">3</Impact><Service display="Applications" type="String">Applications</Service></instance></model></RetrieveIncidentResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

3. Update incident IM10002 curl SOAP:
curl -XPOST -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: "Update"" -H "Authorization: Basic ZmFsY29uOjE=" -d "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ns='http://schemas.hp.com/SM/7'> <soapenv:Header/> <soapenv:Body> <ns:UpdateIncidentRequest attachmentInfo='false' attachmentData='false' ignoreEmptyElements='true'> <ns:model> <ns:keys> <ns:IncidentID>IM10002</ns:IncidentID> </ns:keys> <ns:instance> <Urgency type='String'>2</Urgency> <ns:JournalUpdates> <ns:JournalUpdates>Another update to the activity log, but reassigning back to the raising group</ns:JournalUpdates> </ns:JournalUpdates> </ns:instance> </ns:model> </ns:UpdateIncidentRequest> </soapenv:Body> </soapenv:Envelope>" "http://localhost:13941/SM/7/"

response:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<UpdateIncidentResponse xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" message="Success" returnCode="0" schemaRevisionDate="2014-12-07" schemaRevisionLevel="6" status="SUCCESS" xsi:schemaLocation="http://schemas.hp.com/SM/7 /Incident.xsd">
<model>
<keys>
<IncidentID type="String">IM10002</IncidentID>
</keys>
<instance recordid="IM10002 - Not able to print due to lack of ink in printer." uniquequery="number=&quot;IM10002&quot;">
<IncidentID type="String">IM10002</IncidentID>
<Category type="String">incident</Category>
<OpenTime type="DateTime">2013-12-30T03:07:46+00:00</OpenTime>
<OpenedBy type="String">falcon</OpenedBy>
<Urgency type="String">2</Urgency>
<UpdatedTime type="DateTime">2016-04-22T06:53:09+00:00</UpdatedTime>
<AssignmentGroup type="String">Office Supplies (North America)</AssignmentGroup>
<Description type="Array">
<Description type="String">Seldom ink exist in printer, there's alway error, when printing.111</Description>
</Description>
<Assignee type="String">Change.Coordinator</Assignee>
<Contact type="String">AARON, JIM</Contact>
<JournalUpdates type="Array">
<JournalUpdates type="String">04/22/16 00:53:09 US/Mountain (Jennifer Falcon):</JournalUpdates>
<JournalUpdates type="String">Another update to the activity log, but reassigning back to the raising group</JournalUpdates>
<JournalUpdates type="String">The Incident will be automatically unsuspended at 04/13/16 00:00:00</JournalUpdates>
</JournalUpdates>
<AlertStatus type="String">SLA BREACH</AlertStatus>
<Company type="String">advantage</Company>
<Title type="String">Not able to print due to lack of ink in printer.</Title>
<UpdatedBy type="String">falcon</UpdatedBy>
<Status type="String">Assign</Status>
<Phase type="String">Categorization</Phase>
<Area type="String">access</Area>
<Subarea type="String">authorization error</Subarea>
<Impact type="String">3</Impact>
<Service display="Printing (North America)" type="String">Printing (North America)</Service>
</instance>
</model>
<messages>
<cmn:message type="String">US/Mountain 04/22/16 00:53:09: Incident IM10002 has been updated by falcon</cmn:message>
<cmn:message type="String">Incident record updated.</cmn:message>
</messages>
</UpdateIncidentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

4. Create a new incident curl SOAP:
curl -XPOST -H "Content-Type: text/xml;charset=UTF-8" -H "SOAPAction: "Create"" -H "Authorization: Basic ZmFsY29uOjE=" -d "<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:CreateIncidentRequest attachmentInfo='?' attachmentData='?' ignoreEmptyElements='true'> <ns:model> <ns:keys> </ns:keys> <ns:instance> <ns:Category type='String'>incident</ns:Category> <ns:OpenTime type='DateTime'>2013-12-30T03:07:46+00:00</ns:OpenTime> <ns:OpenedBy type='String'>falcon</ns:OpenedBy> <ns:Urgency type='String'>2</ns:Urgency> <ns:AssignmentGroup type='String'>Office Supplies (North America)</ns:AssignmentGroup> <ns:Description type='Array'> <ns:Description type='String'>Seldom ink exist in printer, there's alway error, when printing.11</ns:Description> </ns:Description> <ns:Assignee type='String'>Change.Coordinator</ns:Assignee> <ns:Contact type='String'>AARON, JIM</ns:Contact> <ns:AlertStatus type='String'>SLA BREACH</ns:AlertStatus> <ns:Company type='String'>advantage</ns:Company> <ns:Title type='String'>Not able to print due to lack of ink in printer.</ns:Title> <ns:UpdatedBy type='String'>falcon</ns:UpdatedBy> <ns:Status type='String'>Assign</ns:Status> <ns:Phase type='String'>Categorization</ns:Phase> <ns:Area type='String'>access</ns:Area> <ns:Subarea type='String'>authorization error</ns:Subarea> <ns:Impact type='String'>3</ns:Impact> <ns:Service display='Printing (North America)' type='String'>Printing (North America)</ns:Service> </ns:instance> </ns:model> </ns:CreateIncidentRequest> </soapenv:Body> </soapenv:Envelope>" "http://localhost:13941/SM/7/"

response:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<CreateIncidentResponse xmlns="http://schemas.hp.com/SM/7" xmlns:cmn="http://schemas.hp.com/SM/7/Common" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" message="Success" returnCode="0" schemaRevisionDate="2014-12-07" schemaRevisionLevel="6" status="SUCCESS" xsi:schemaLocation="http://schemas.hp.com/SM/7 /Incident.xsd">
<model>
<keys>
<IncidentID type="String">IM10216</IncidentID>
</keys>
<instance recordid="IM10216 - Not able to print due to lack of ink in printer." uniquequery="number=&quot;IM10216&quot;">
<IncidentID type="String">IM10216</IncidentID>
<Category type="String">incident</Category>
<OpenTime type="DateTime">2013-12-30T03:07:46+00:00</OpenTime>
<OpenedBy type="String">falcon</OpenedBy>
<Urgency type="String">2</Urgency>
<UpdatedTime type="DateTime">2016-04-22T06:54:55+00:00</UpdatedTime>
<AssignmentGroup type="String">Office Supplies (North America)</AssignmentGroup>
<Description type="Array">
<Description type="String">Seldom ink exist in printer, there's alway error, when printing.11</Description>
</Description>
<Assignee type="String">Change.Coordinator</Assignee>
<Contact type="String">AARON, JIM</Contact>
<AlertStatus type="String">SLA BREACH</AlertStatus>
<Company type="String">advantage</Company>
<Title type="String">Not able to print due to lack of ink in printer.</Title>
<UpdatedBy type="String">falcon</UpdatedBy>
<Status type="String">Assign</Status>
<Phase type="String">Categorization</Phase>
<Area type="String">access</Area>
<Subarea type="String">authorization error</Subarea>
<Impact type="String">3</Impact>
<Service display="Printing (North America)" type="String">Printing (North America)</Service>
</instance>
</model>
<messages>
<cmn:message type="String">US/Mountain 04/22/16 00:54:55: Incident IM10216 has been opened by falcon</cmn:message>
<cmn:message type="String">Incident "IM10216" added.</cmn:message>
</messages>
</CreateIncidentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Highlighted
Visitor.

Hi 

 

 

View solution in original post

0 Likes
Highlighted
Visitor.

Thank you very much Lingyanmeng, It worked for me.

 

Kudos....

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Glad to know it helps.

0 Likes
Highlighted
Absent Member.
Absent Member.

Hi lingyanmeng,

I have a RESTful attachment API question and hope you can help. I need to send attachment (pdf, xls, etc) to an existing HPSM incident ticket from third party application. I can encode the attachment to base64 but I don't know where to put the encoded attachemnt  in the REST request message when I sent it over to HPSM. 

I saw your example in this thread to upload the attachment to HPSM. Do you have any example how I can send the encoded base64 attachment via curl? Your help is appreciated. 

Thanks,

Jason

0 Likes
Highlighted
New Member.

hi

Please, try to update characters öäå / ÖÄÅ too to Hp Service manager. I have  added  -H "Content-Type:application/json;charset=utf-8"  , but  these special characters will not come to incident.

update an incident by curl :

curl -x "yourproxyserver:port" -XPOST -H "Authorization: Basic base64usernamepassword" -H "Accept-Encoding: gzip,deflate" -H "Content-type: application/json;charset=utf-8" -d "{ 'Incident': { 'JournalUpdates': [ '08/04/08 12:54:14 US/Mountain (falcon):', 'testing characters öäå / ÖÄÅ ', '08/04/08 12:54:14 US/Mountain (falcon):', 'test' ], 'Urgency' : '4' } }" "http://yourSMurl:13080/SM/9/rest/incidents/IM10002"

Many thanks !

Jouni

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.