Question

I am following RegOnline's developer pages to set up an API call to our server. They offer various examples of how to handshake (PHP, C#, JS, SOAP), the last one has the poorest example of how to include an API token as part of a method call.

http://developer.regonline.com/authentication-basics/

I am trying to call their GetEvent method, and this call has to include an API token that I have generated. However, based on their SOAP example, I am left guessing as to how to include the value of token. The following is their example:

<s:complexType name="TokenHeader">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="APIToken" type="s:string"/>
  </s:sequence>
  <s:anyAttribute/>
</s:complexType>

The other examples on the page have full versions that show explicitly where you could hard code the token if you had to. I will admit my knowledge of SOAP is minimal currently so perhaps I'm missing something in this example.

Here is my attempt to call the method. It only spits out a page of their documentation and a 200 OK status, which is not right.

<cfset apiToken = "xxxxx" />
<cfset eventID = "xxxxxx" />
    <cfsavecontent variable="soapBody">
        <cfoutput>

            <?xml version="1.0" encoding="utf-8"?>  
            <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">

                <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

                    <GetEvent xmlns="http://www.regonline.com/api">

                        <eventID>#eventID#</eventID>

                    </GetEvent>

                </s:Body>

            </s:Envelope>

            <s:complexType name="TokenHeader">
                <s:sequence>
                    <s:element minOccurs="0" maxOccurs="1" name="APIToken" type="s:string">
                        #apiToken#
                    </s:element>
                </s:sequence>
                <s:anyAttribute/>
            </s:complexType>

        </cfoutput>
    </cfsavecontent>

    <cfhttp url="https://www.regonline.com/api" method="get" result="theCFHTTP" redirect="true">

        <cfhttpparam type="HEADER" name="Content-Type" value="text/xml; charset=utf-8">
        <cfhttpparam type="HEADER" name="Accept" value="application/soap+xml, multipart/related, text/*">
        <cfhttpparam type="HEADER" name="User-Agent" value="Axis/1.1">
        <cfhttpparam type="HEADER" name="Cache-Control" value="no-cache">
        <cfhttpparam type="HEADER" name="Pragma" value="no-cache">
        <cfhttpparam type="HEADER" name="SOAPAction" value="https://www.regonline.com/api/default.asmx/GetEvent">
        <cfhttpparam type="HEADER" name="Content-Length" value="#len(soapBody)#">
        <cfhttpparam type="xml" name="body" value="#soapBody#">

    </cfhttp>

    <cfdump var="#theCFHTTP#">
Was it helpful?

Solution 2

That's sort of not what you want to do. With SOAP calls, you just follow the XML they provided in the documentation (https://www.regonline.com/api/default.asmx?op=GetEvent).

So in the particular case, you want to replace the CSSAVECONTENT variable soapBody to below:

<cfsavecontent variable="soapBody">
<cfoutput>
    <?xml version="1.0" encoding="utf-8"?>
    <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/">
        <soap:Header>
            <TokenHeader xmlns="http://www.regonline.com/api">
                <APIToken>#apiToken#</APIToken>
            </TokenHeader>
        </soap:Header>

        <soap:Body>
            <GetEvent xmlns="http://www.regonline.com/api">
                <eventID>#eventID#</eventID>
            </GetEvent>
        </soap:Body>
    </soap:Envelope>
</cfoutput>
</cfsavecontent>

See what that returns for you.

OTHER TIPS

Your SOAP request is in a wrong format. All of the SOAP request should be within the SOAP envelope. Here is the template created in SoapUI for the getEvent request.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://www.regonline.com/api">
  <soapenv:Header>
    <api:TokenHeader>
      <!--Optional:-->
      <api:APIToken>?</api:APIToken>
   </api:TokenHeader>
  </soapenv:Header>
  <soapenv:Body>
    <api:GetEvent>
      <api:eventID>?</api:eventID>
    </api:GetEvent>
  </soapenv:Body>
</soapenv:Envelope>

For the call itself, you may need to try post over get, but I'm unsure about this. The one thing I think you might need to update is the SOAPAction. In my test call in SoapUI, the action in the header was http://www.regonline.com/api/GetEvent. Though it may work both ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top