nyconfidential
New Member
- Joined
- Jul 22, 2015
- Messages
- 49
- Office Version
- 365
- 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.
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>
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>