Empty body on successful connection for HTTR API call

After slugging through various issues on connections I was able to put a successful connection together for the API below.
However, the response is coming back empty.
It would be awesome if someone could question/comment/curse the below.
I am providing XML to a web services system.

I have been able to successfully run and get results back using postman but have had some struggles on hard coding the API call in R.

On a side note, i have a whole new appreciation for REST APIs. This SOAP messing is killing me.

Thank you all again,
Jarrod Brown


body_content <-  '<?xml version="1.0" encoding="UTF-8"?> 
                  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.xxxxxxxx.com/bizconnect/SBU">
                  <SOAP-ENV:Body>
                    <ns1:GetSBUApplicationData>
                      <ns1:Subscriber>
                           <ns1:SubCode>123456</ns1:SubCode>
                      </ns1:Subscriber>
                      <ns1:UserID>xxxxxx</ns1:UserID>
                      <ns1:ReferenceID>A</ns1:ReferenceID>
                      <ns1:ResponseVersion>010</ns1:ResponseVersion>
                      <ns1:Application>
                          <ns1:Id>G020D</ns1:Id>
                          <ns1:Name/>
                          <ns1:Key>
                              <ns1:Field>
                                  <ns1:Id>00920000</ns1:Id>
                                  <ns1:Name/>
                                  <ns1:Value>700000002</ns1:Value>
                              </ns1:Field>
                          </ns1:Key>
                      </ns1:Application>
                    </ns1:GetSBUApplicationData>
                  </SOAP-ENV:Body>
                  </SOAP-ENV:Envelope>'

test2 <- POST(url = 'https://stg1-ss1.xxxxxxx.com/bizconnect/SBU/service',
              authenticate("user_name", "user_password", type = "basic"),
              add_headers("Content-Type" = "text/xml"),
              body =  body_content,
              config = config(ssl_verifypeer = FALSE),
              content_type("text/xml> ")
             )

It is difficult to know what is going on without being able to test it.

Some remarks:

  • you do not need to provide twice the header with add_header and content_type. Only one of those is necessary
  • httr as a content_type_xml() as a helper to precise that the request as type xml
  • You may need to add in the request something about the result you want. like httr::accept_xml() to send back xml response.

Know that you could try your request on http://httpbin.org to see how the request is formatted. You can then check with what you know is correct if you have other example

library(httr)
test2 <- POST(url = 'http://httpbin.org/post',
              authenticate("user_name", "user_password", type = "basic"),
              add_headers("Content-Type" = "text/xml"),
              body =  body_content,
              config = config(ssl_verifypeer = FALSE),
              content_type("text/xml")
)

Hope it helps

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.