XML call in VBA

nyconfidential

New Member
Joined
Jul 22, 2015
Messages
49
Office Version
  1. 365
  2. 2016
Hey all, I've inherited some code that is making a call to a web api via an XML request that is returning values. I've worked with calls to APIs in VBA in the past, but those were normally just passing one or two parameters into a URL. See the code below, I'm having a difficult time understanding how this works. I'm sending this via a SOAP envelope (see below code) - which seems to consist of the names of all of the fields I am looking to return values for. What I don't get is exactly how this code is returning the correct values. I'm sending the SOAP envelope contents to the URL in question, and it's returning the correct values when I print the responsetext - but I don't understand how, as I don't seem to be providing any relevant search parameters in the envelope. Does anyone know how this is working exactly? Thanks in advance.

VBA Code:
Private Function CallService(ByVal sURL As String, ByVal sMethod As String, ByVal sEnv As String, Optional ByVal nameSpaces As String) As String
    Dim xmlHtp As New MSXML2.XMLHTTP60
    Dim xmlDoc As New DOMDocument60
    
    With xmlHtp
        .Open "post", sURL, False
        .setRequestHeader "Host", GetHost(sURL)
        .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
        If sMethod = "CallWorkflow" Then
            .setRequestHeader "soapAction", "http://tempuri.org/" & sMethod
        Else
            .setRequestHeader "soapAction", "http://tempuri.org/StepWise/Service1/" & sMethod
        End If
        .setRequestHeader "withCredentials", "true"
        .send sEnv
        
        Debug.Print .responseText & vbCrLf
        xmlDoc.LoadXML .responseText 
   
       
    End With

End Function

SOAP envelop contents(what Im sending to the API):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="Stargazing by the shore"><soapenv:Header/><soapenv:Body><ser:XMLCall><ser:SessionID><![CDATA[643ee6c7-fe27-49bb-8841-22057236cf4a]]></ser:SessionID><ser:XMLDocument><![CDATA[<StepWise><Quote><GetQuoteValues><Step Name="ParentGroup" /><Step Name="BlockID" /><Step Name="GroupName" /><Step Name="EffDate" /><Step Name="Source_OrigEffDt" /><Step Name="Bens_CalcPlanID" /><Step Name="Bens_CalcPlanID_Rx" /><Step Name="CenSum_TotSubsNoVar" /><Step Name="Renl_TotCurPlanManl_Med" /><Step Name="Source_CurMedPrem" /><Step Name="Source_CurStepPrem" /><Step Name="Renl_TotCurPlanManl_Dent" /><Step Name="Source_CurDenPrem" /><Step Name="RateOV_AffilTrustFactor" /><Step Name="SIC_MedFactor" /><Step Name="BT_PPOFx_Emp" /><Step Name="BT_AgeFx_EE" /><Step Name="BT_AgeFx_SP" /><Step Name="BT_AgeFx_CH" /><Step Name="BT_AgeFx_FAM" /><Step Name="BT_GenderFx_EE" /><Step Name="BT_GenderFx_SP" /><Step Name="BT_GenderFx_CH" /><Step Name="
BT_GenderFx_FAM" /><Step Name="BT_SizeFx" /><Step Name="BT_AreaFx" /><Step Name="GenAgent" /><Step Name="Renl_CurPlanManl_Vis" /><Step Name="Renl_CurPlanManl_STD" /><Step Name="Renl_CurPlanManl_Life" /><Step Name="Renl_CurPlanManl_ADD" /><Step Name="GroupSize" /></GetQuoteValues></Quote></StepWise>]]></ser:XMLDocument></ser:XMLCall></soapenv:Body></soapenv:Envelope>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top