Jump to content

REST API - Post XML data with HTTP


Chris86
 Share

Recommended Posts

Hello,

I'm in the making of a script that needs to post XML data through HTTPS to our ServiceDesk Plus MSP service. I'm running into trouble because I have never made any scripts using HTTP with POST and I cannot see what I'm doing wrong here.

Can someone help me or should I find help somewhere else?

$URLSDP="" ;REMOVED - cannot publish this. this is the HTTPS url to our ServiceDesk
$TechnicianKey="" ;REMOVED
$ID="" ; Request ID

$sPostData = "OPERATION_NAME=ADD_NOTE&INPUT_DATA=<Operation><Details><Notes><Note><isPublic>false</isPublic><notesText>Text added to the note</notesText></Note></Notes></Details></Operation>&format=XML"
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", $URLSDP & "/sdpapi/request/"& $ID & "/note?TECHNICIAN_KEY="& $TechnicianKey, False)
$oHTTP.SetRequestHeader("Content-Type", "xml")
$oHTTP.Send($sPostData)
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

ConsoleWrite($oStatusCode & @CRLF)
ConsoleWrite($oReceived & @CRLF)
If $oStatusCode = 200 Then
    ;Process the response $oReceived
    ;ConsoleWrite(@CRLF & "Response" & @CRLF & $oReceived & @CRLF)
Else
    MsgBox(16, "Error " & $oStatusCode, $oReceived, 7)
EndIf

Response:

<operation name="POST"><result><status>Failed</status><message>Invalid operation</message></result></operation>

REST API guide.

https://www.manageengine.com/products/service-desk-msp/help/adminguide/api/notes-operations.html#add

 

Edited by Chris86
Link to comment
Share on other sites

Search for some HttpDebugger to see how exactly header look like.

I suggest you to do something like this:

$objHTTP.open ("POST", "url", False)
$objHTTP.setRequestHeader ("Content-Type", "text/xml;charset=UTF-8")
$objHTTP.setRequestHeader("Content-Length",StringLen($YourXMLText))
$objHTTP.setRequestHeader("Connection","If is needed")
$objHTTP.setRequestHeader("User-Agent","If is needed")
$objHTTP.send ($YourXMLText)

Saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...