ruby-on-railssoapsavon

Issues Formatting a SOAP API with Savon gem


I was terrified this day would come.. dealing with SOAP API's...

This is a whole new realm for me, Ive done some digging with the SAVON gem but i cant seem to structure my call..

Essentially what I am trying to do is the following:

Step 1: Call the API to retrieve the LatestCallerVersion (API Version)

Step 2: Take the LatestCallerVersion and send a second request to the validation API to see if my customers are in a valid service area.

This is what I've come up with (but it crashes and burns hard)

caller_client = Savon.client(
  wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL '\
)
caller_response = caller_client.call(
  :authentication,
  message: {
      user: 'xxxxxx',
      password: 'xxxxxx',
      two_factor_device_id: 'xxxxxx'
  },
  :body,
  message: {
      :get_latest_caller_version
  }
)

Here is the SOAP request & response Doc for the GetLatestCaller call

POST /webservices/CustomerManagement.asmx HTTP/1.1
Host: alarmadmin.alarm.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <Authentication xmlns="http://www.alarm.com/WebServices">
      <User>string</User>
      <Password>string</Password>
      <TwoFactorDeviceId>string</TwoFactorDeviceId>
    </Authentication>
  </soap12:Header>
  <soap12:Body>
    <GetLatestCallerVersion xmlns="http://www.alarm.com/WebServices" />
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <GetLatestCallerVersionResponse xmlns="http://www.alarm.com/WebServices">
      <GetLatestCallerVersionResult>int</GetLatestCallerVersionResult>
    </GetLatestCallerVersionResponse>
  </soap12:Body>
</soap12:Envelope>

Here is the CheckCaller_V2 request & Response

POST /webservices/Validate.asmx HTTP/1.1
Host: alarmadmin.alarm.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <Authentication xmlns="http://www.alarm.com/WebServices">
      <User>string</User>
      <Password>string</Password>
      <TwoFactorDeviceId>string</TwoFactorDeviceId>
    </Authentication>
  </soap12:Header>
  <soap12:Body>
    <CheckCoverage_v2 xmlns="http://www.alarm.com/WebServices">
      <input>
        <Address>
          <Street1>string</Street1>
          <Street2>string</Street2>
          <SubCity>string</SubCity>
          <City>string</City>
          <SubState>string</SubState>
          <State>string</State>
          <Zip>string</Zip>
          <CountryId>Canada</CountryId>
        </Address>
        <Network>Gsm</Network>
        <Generation>FourG</Generation>
        <CallerVersion>returned from GetLatestCaller call</CallerVersion>
      </input>
    </CheckCoverage_v2>
  </soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <CheckCoverage_v2Response xmlns="http://www.alarm.com/WebServices">
      <CheckCoverage_v2Result>NotChecked or FullCoverage or MostlyCovered or NoCoverage or Error or BadZip or PartialCoverage or NotSupported or NotOffered</CheckCoverage_v2Result>
    </CheckCoverage_v2Response>
  </soap12:Body>
</soap12:Envelope>

I am brand new to SOAP Any assistance here would be greatly appreciated. Please let me know if anything further is needed.


Solution

  • kindly use SOAP UI to check for the Request definition. On loading the the WSDL file in SOAP UI, I am able to get the following. Loading to SOAP UI

    After that it becomes relatively easy to follow along. It seems all the operations has the same header, so I will go and create a client that looks like

    caller_client = Savon.client(
              wsdl: 'https://alarmadmin.alarm.com/webservices/CustomerManagement.asmx?WSDL',
              env_namespace: :soapenv,
              namespace_identifier: :web,
              soap_header: {
                'web:Authentication': {
                  'web:User': 'xxxx',
                  'web:Password': 'xxxxx',
                  'web:TwoFactorDeviceId': 'xxx'
                }
              })
    

    And after that calling the individual operation becomes

    caller_client.call(:get_latest_caller_version)
    

    If you want to list all the possible operations, you can use

    caller_client.operations
    

    If you want to pass message to individual operation, use the following format

       caller_client.call(:get_modem_serial_from_iccid, message: { iccid: 'xxxx' })