Angelos PaaS4SaaS Blog

Wednesday, 1 July 2015

Calling Fusion SOAP Services from Ruby

Just completed some integration work with a partner of ours using the Ruby language. Given that a lot of startups like Ruby I thought it would be useful to cut-n-paste the sample code here.
This example creates a simple (minimal) opportunity using the SOAP API in Sales Cloud. That said the code would be almost identical if you were querying HCM Data,
The approach we took here was to prototype the SOAP call using SOAPUI and then cut-n-paste the SOAP payload into the data variable. In a real industrialized solution I'd create the payloads in template form.


  def create_opportunity

  # Change yourhostname.com to your Fusion SOAP Endpoint Hostname

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    path = uri.request_uri
    http.read_timeout = 5
    http.open_timeout = 5


  # Change authorization header to contain Base64encoded string of username/password
    headers = {
    'Content-Type' => 'text/xml',
    'authorization' => 'Basic bBase64EncodedCredentialHere='
    }

   
   # Data Contains the payload
    <soapenv:Header/>
    <soapenv:Body>
    <typ:createOpportunity>
    <typ:opportunity>
    <opp:Name>Joel Test New1</opp:Name>
    </typ:opportunity>
    </typ:createOpportunity>
    </soapenv:Body>
    </soapenv:Envelope>'

    resp, data = http.post(path, data, headers)
  end

!TIP!
A quick test in a SOAP testing tool like JDevelopers Http Analyzer or SOAPUI is a MUST before executing this!

No comments:

Post a Comment