cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
854
Views
0
Helpful
0
Replies

Issues in UCCX Rest API to upload a XML File

sjgreen
Level 1
Level 1

I Have successfully uploaded a file with the UCCX API's using Postman using the two-step process UPLOAD and save and it works well. However, I have to now convert this into a working VBScript ASP. I have had some success in the fact that on upload I get a success 201 however I hit an issue when I'm trying to save the file the correct directory in the repository. Any help would be great, I'm so stuck now..

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><apiErrors><apiError><errorData>InternalServerError</errorData><errorMessage>:upload:failed:/en_GB/XMLFILES/88000805.XML</errorMessage><errorType>InternalServerError</errorType></apiError></apiErrors>

 

this is the code I use to upload and save -

 

'Session ("username") provides the filename-88000805

SaveXMLPath = "../XML/" & (Session ("username") & ".XML")

strXMLFile = server.MapPath(SaveXMLPath)
fileNameString = (Session ("username") & ".XML")

fileandpath = chr(34) & strXMLFile & chr(34)
'Create Stream object
Dim requestbody
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
Set HTTP1 = CreateObject("MSXML2.XMLHTTP")
BinaryStream.Type = 2
BinaryStream.CharSet = "UTF-8"
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile strXMLFile
'Open the stream And get data from the object
fileContents = BinaryStream.ReadText

requestbody = requestbody & "--------------------------508309700500341664831116" & vbCrLf & "Content-Disposition: form-data; name=""file""; filename=" & fileandpath & vbCrLf & "Content-Type: application/xml" & vbCrLf & fileContents & vbCrLf & "--------------------------508309700500341664831116" & vbCrLf & "Content-Disposition: form-data; name=""mimetype""" & vbCrLf & vbCrLf & "multipart/form-data" & vbCrLf & "--------------------------508309700500341664831116--"

HTTP1.Open "POST", ("http://test-itps-uccx01.test.local/adminapi/document/uploadFile/") , false
HTTP1.setRequestHeader "cache-control", "no-cache"
HTTP1.setRequestHeader "Authorization", "Basic stringstringstringstringstringstring="
HTTP1.setRequestHeader "Accept" , "*/*"
HTTP1.setRequestHeader "Host" , "test-itps-uccx01.test.local"
HTTP1.setRequestHeader "accept-encoding", "gzip, deflate"
HTTP1.setRequestHeader "content-type", "multipart/form-data; boundary=------------------------508309700500341664831116"
HTTP1.setRequestHeader "content-length" , len(requestbody)
HTTP1.send requestbody

Response.write " UPLOAD" & len(requestbody) & fileContents & vbCrLf & HTTP1.responseText

BinaryStream.Close
Set BinaryStream = nothing

dteWait = DateAdd("s", 2, Now())
Do Until (Now() > dteWait)
Loop
dteWait = null

' ---- put upload file to document store in UCCX ----

Set HTTP2 = CreateObject("MSXML2.XMLHTTP")

HTTP2.Open "POST", ("http://test-itps-uccx01.test.local/adminapi/document/") , false

HTTP2.setRequestHeader "cache-control", "no-cache"
HTTP2.setRequestHeader "Authorization", "Basic stringstringstringstringstringstring="
HTTP2.setRequestHeader "Content-Type", "application/xml"
HTTP2.send "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf & "<Files xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" & vbCrLf & "xsi:noNamespacesSchemaLocation=""../adminapi/src/main/resources/xsd/Files.xsd"">" & vbCrLf & "<Document>" & vbCrLf & "<File>" & vbCrLf & " <path>/en_GB/XMLFILES/</path>" & vbCrLf & "<FileName>" & fileNameString & "</FileName>" & vbCrLf & "</File>" & vbCrLf & "</Document>" & vbCrLf & "</Files>"

Response.write " SAVE" & vbCrLf & HTTP2.responseText & vbCrLf

 

0 Replies 0
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: