0

I am trying to get the SOAP login method working with the API for Vertical Response using VBA in Access. They do not promote VBA with examples, and they suggest using the tools and examples they support, like those in Java and PHP.

On their API Documentation page at http://developers.verticalresponse.com/api/, they say the endpoint is: https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl

On their API Documentation page, the link describing the login is on the Misc Methods tab.

Input arguments are described as:

username [xsd:string]
password [xsd:string]
session_duration_minutes [xsd:integer] 

I have tried the following VBA code, with variations for the URL, the SOAP envelope, and the headers. I have never gotten a session ID, but always useless text shown below.

Function VRLogin() As String

   Dim sURL As String
   Dim sEnv As String
   Dim xmlhtp As New MSXML2.XMLHTTP

   sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI"

   sEnv = sEnv & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
   sEnv = sEnv & "  <soap:Body>"
   sEnv = sEnv & "    <username>[email protected]</username>"
   sEnv = sEnv & "    <password>xxxxxxxx</password>"
   sEnv = sEnv & "    <session_duration_minutes>120</session_duration_minutes>"
   sEnv = sEnv & "  </soap:Body>"
   sEnv = sEnv & "</soap:Envelope>"

   xmlhtp.Open "post", sURL, False
   xmlhtp.setRequestHeader "Content-Type", "text/xml"

   xmlhtp.setRequestHeader "SOAPAction", "login"
   xmlhtp.send sEnv

   VRLogin = xmlhtp.ResponseText

 End Function

With the following variations in the URL:

 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI"
 sURL = "https://api.verticalresponse.com/wsdl/1.0/login"
 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI/login"
 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI?method=login"
 sURL = "https://api.verticalresponse.com/login"

The response text is similar to the following:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /wsdl/1.0/VRAPI was not found on this server.<P>
</BODY></HTML>

If the URL contains "wsdl" like one of the following:

 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl"
 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl/login"
 sURL = "https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl?method=login"

The response text is the wsdl document:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:vrns="http://api.verticalresponse.com/1.0/VRAPI" xmlns:vrtypens="http://api.verticalresponse.com/1.0/VRAPI.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:vr="http://www.verticalresponse.com/vrns" targetNamespace="http://api.verticalresponse.com/1.0/VRAPI" name="VRAPI">
  <wsdl:types>
    <xsd:schema targetNamespace="http://api.verticalresponse.com/1.0/VRAPI.xsd">
      <xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
      <xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <xsd:complexType name="ArrayOfCampaignContentLink">
    <xsd:complexContent>
        <xsd:restriction base="soapenc:Array">
            <xsd:attribute ref="soapenc:arrayType" wsdl:arrayType="vrtypens:CampaignContentLink[]"/>
        </xsd:restriction>
    </xsd:complexContent>
</xsd:complexType>

etc ...

I also tried adding "xsd:" to the SOAP envelope, as I have even seen in some examples, which did not help, like:

 sEnv = sEnv & "    <xsd:username>[email protected]</xsd:username>"
 sEnv = sEnv & "    <xsd:password>xxxxxxxx</xsd:password>"
 sEnv = sEnv & "    <xsd:session_duration_minutes>120</xsd:session_duration_minutes>"

I modified headers, like the Content-type, removed headers, and made a fully qualified SOAPAction header like the following, without success:

 xmlhtp.setRequestHeader "SOAPAction", "https://api.verticalresponse.com/wsdl/1.0/VRAPI/login"

My API access has been enabled, but my results are showing that I am not even getting that far in authenticating. I think this is a problem in either the URL, the SOAP envelope, or the headers.

From the information they provide for the endpoint and the login with its inputs, it seems I should be able to set up an API call using VBA. This question should not be specific to the Vertical Response API.

Can anybody see what I am missing?

ALSO: This may be a different question, but it is related, and needed to call the API.

How do you pass an array in a SOAP envelope?

1 Answer 1

0

I found the answer.

My main problem was that I was using the endpoint URL that they published on their web page to call their API. However I needed to download this .wsdl file at this URL, and then look inside and see the real URL to call the API, which is https://api.verticalresponse.com/1.0/VRAPI. The .wsdl file also tells you the proper SOAP action names to use. You also need to specify namespaces properly.

The following is the finished working result.

Function VRLogin() As String

   Dim sURL As String
   Dim sEnv As String
   Dim xmlhtp As New MSXML2.XMLHTTP

   sURL = "https://api.verticalresponse.com/1.0/VRAPI"

   sEnv = "<?xml version=""1.0"" encoding=""UTF-8""?>"
   sEnv = sEnv & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ns1=""VR/API/1_0"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:ns2=""http://api.verticalresponse.com/1.0/VRAPI.xsd"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">"
   sEnv = sEnv & "    <SOAP-ENV:Body>"
   sEnv = sEnv & "        <ns1:login>"
   sEnv = sEnv & "            <args xsi:type=""ns2:loginArgs"">"
   sEnv = sEnv & "                <username xsi:type=""xsd:string"">[email protected]</username>"
   sEnv = sEnv & "                <password xsi:type=""xsd:string"">xxxxxxxx</password>"
   sEnv = sEnv & "                <session_duration_minutes xsi:type=""xsd:integer"">120</session_duration_minutes>"
   sEnv = sEnv & "            </args>"
   sEnv = sEnv & "        </ns1:login>"
   sEnv = sEnv & "    </SOAP-ENV:Body>"
   sEnv = sEnv & "</SOAP-ENV:Envelope>"

   xmlhtp.Open "post", sURL, False
   xmlhtp.setRequestHeader "Content-Type", "text/xml"

   xmlhtp.setRequestHeader "SOAPAction", "VR/API/1_0#login"
   xmlhtp.send sEnv

   VRLogin = xmlhtp.ResponseText

End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.