Grüß’ Euch alle,
dieser Post lässt mich hoffen, dass mir hier vielleicht jemand weiterhelfen kann.
In einem Event-Skript habe ich testweise eine Funktion angelegt um per API ein neues Dokument in enaio abzulegen. Ich habe die „alte“ AppConnector-API verwendet, weil ich beim neuen DMS Service beim Aufruf von POST /api/dms/objects immer ein „method not implemented“ erhalte.
Die AppConnector-Api läuft bei mir aber auch immer auf einen 500er hinaus.
Vielleicht mache ich was ganz falsch.
Hier meine Funktion:
sub writeDataToNewFile(input_location, input_filename, input_content)
msgBox "Create File: " & input_filename & " in FolderID " & input_location
Set object_XMLHTTP = CreateObject("MSXML2.ServerXMLHTTP.6.0")
enaio_endpoint = "http://er-anw-enaiotest.kbit.intern/osrest/api/documents/insert/" & input_location
dim request_body, request_boundary, request_metadata, const_ObjectTypeID, const_Cabinet, currentDate
' assemble the metadata
const_ObjectTypeID = 262145 'Object Type ID of "Akte:Dokument"
const_Cabinet = "Akte"
currentDate = now()
request_metadata = "{""data"": {"
request_metadata = request_metadata & """cabinet"": """ & const_Cabinet & ""","
request_metadata = request_metadata & """objectTypeId"": """ & const_ObjectTypeID & ""","
request_metadata = request_metadata & """fields"": {"
request_metadata = request_metadata & """MAIL_SUBJECT"": {""value"": """ & input_filename & """},"
request_metadata = request_metadata & """MAIL_SUBMIT_TIME"": {""value"": """ & dateString(currentDate) & """}"
request_metadata = request_metadata & "}"
request_metadata = request_metadata & "}}"
'assemble the request_body
request_boundary = "----webKitFormBoundary8IMRZEG5U0UOXO3W"
request_body = "--" & request_boundary & vbCrLf
request_body = request_body & "Content-Disposition: form-data; name=""metadata""" & vbCrLf
request_body = request_body & "Content-Type: application/json" & vbCrLf & vbCrLf
request_body = request_body & request_metadata & vbCrLf
request_body = request_body & "--" & request_boundary & vbCrLf
request_body = request_body & "Content-Disposition: form-data; name=""file""" & vbCrLf
request_body = request_body & "Content-Type: application/octet-stream" & vbCrLf
request_body = request_body & "Content-Transfer-Encoding: base64" & vbCrLf & vbCrLf
request_body = request_body & input_content & vbCrLf
request_body = request_body & "--" & request_boundary & "--" & vbCrLf
writeToDebugFile(request_body)
' Open the connection
object_XMLHTTP.open "POST", enaio_endpoint, true
' Set the headers
object_XMLHTTP.setRequestHeader "Content-Type", "multipart/form-data"
object_XMLHTTP.setRequestHeader "Authorization", "Basic ...="
' Send the request with the JSON payload
object_XMLHTTP.send request_body
' Wait until the response is fully received
while object_XMLHTTP.readyState <> 4
object_XMLHTTP.waitForResponse(1) 'Pause for 1 second before checking the readyState again
wend
httpStatus = object_XMLHTTP.Status
if httpStatus = 200 then
msgBox object_XMLHTTP.responseText
else
msgBox "Es ist ein Fehler bei der Kommunikation mit der enaio-API aufgetreten. HTTP Status: " & httpStatus & " " & object_XMLHTTP.StatusText
writeToDebugFile object_XMLHTTP.responseText
end if
end sub
Zum Hintergrund: Ich erhalte den input_content als base64-Blob aus einem anderen Api-Aufruf - und fände es am besten, diesen Blob direkt als neues Dokument in enaio abzulegen.
Die von mir in writeToDebugFile generierte Datei sieht etwa so aus:
------webKitFormBoundary8IMRZEG5U0UOXO3W
Content-Disposition: form-data; name="metadata"
Content-Type: application/json
{"data": {"cabinet": "Akte","objectTypeId": "262145","fields": {"MAIL_SUBJECT": {"value": "Kopfbogen_ER.docx"},"MAIL_SUBMIT_TIME": {"value": "27.06.2024"}}}}
------webKitFormBoundary8IMRZEG5U0UOXO3W
Content-Disposition: form-data; name="file"
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
UEsDBBQACAgIA ... base64-encoded blob ... AAAA=
------webKitFormBoundary8IMRZEG5U0UOXO3W--