0

How to upload XML sheet details through API. While I'm using below given VBA code I get an error like certification error.

Sub HTTPPost()
  'create an xml object
    Dim oXML As Object
    Set oXML = CreateObject("MSXML2.DOMDocument")

    oXML.async = False

    Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    oHTTP.setOption(2) = (oHTTP.getOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
    oHTTP.Open "POST", "https://isp-api-is1-test.prg-dc.com/gateway/CustomerOrder/1.0/CustomerOrder", False
    oHTTP.setRequestHeader "Username_IT", "onLwEa54"
    oHTTP.setRequestHeader "Content-Type", "application/xml"
    oHTTP.setRequestHeader "Accept", "application/xml"
    oHTTP.setRequestHeader "APIKey", "163c4821-5a6c-499e-9a9c-ca8b5659e530"
    oXML.Load ("C:\Users\nypaul\Downloads\API_CustomerOrder_AFR_V1_52.xml")
    oHTTP.send oXML
End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
nie
  • 7
  • 1
  • 4
  • The above won't compile for me (as I have Option Explicit on). Please put Option Explicit at the top of yur module and declare all your variables and show their assignments (or masked assignments). For example, what is SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS ? Is this declared as a constant somewhere else in your code? – QHarr Jun 04 '18 at 12:26
  • @QHarr, i am hust a newbie in vba can you please show me the sample structure it will be great help for me. – nie Jun 04 '18 at 12:30
  • Looks like you were after something like https://stackoverflow.com/a/11600385/6241235 – QHarr Jun 04 '18 at 12:32
  • Put this at the top of your code as well Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056 https://www.experts-exchange.com/questions/28349681/Ignoring-client-certificate-using-ServerXMLHTTP-VB6.html – QHarr Jun 04 '18 at 12:41

1 Answers1

0

I can't access that address, is it valid?

Otherwise here is the general construct (too long for a comment as is code)

Option Explicit

Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
Sub HTTPPost()
  'create an xml object
    Dim oXML As Object, oHTTP As Object
    Set oXML = CreateObject("MSXML2.DOMDocument")
    oXML.async = False
    Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    oHTTP.SetOption(2) = (oHTTP.GetOption(2) - SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS)
    oHTTP.Open "POST", "https://isp-api-is1-test.prg-dc.com/gateway/CustomerOrder/1.0/CustomerOrder", False
    oHTTP.setRequestHeader "Username_IT", "onLwEa54"
    oHTTP.setRequestHeader "Content-Type", "application/xml"
    oHTTP.setRequestHeader "Accept", "application/xml"
    oHTTP.setRequestHeader "APIKey", "163c4821-5a6c-499e-9a9c-ca8b5659e530"
    oXML.Load ("C:\Users\nypaul\Downloads\API_CustomerOrder_AFR_V1_52.xml")
    oHTTP.send oXML
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101