You need to sign in to do that
Don't have an account?

Passing an HTTP Parameter to a Non-SOAP XML API
I am having trouble writing an Apex class that integrates to a non-SOAP based XML-over-HTTPS web service. The problem is that the API requires an HTTP request parameter (not a header) to be set. Here is their documentation on this:
"To implement the XML Data Integration Toolkit in an application, user must post the request to the Data Integration server with the XML request in a specific parameter.
- Data Integration server URL: https://toolkit.dnb.com/access/scripts/broker.asp
- Parameter name: request"
I naively hoped that the following code would work in an Apex class to access this API (since the HttpRequest Apex class does not have a setParameter() or setField() method -- like the equivalent Java or C# request classes do -- just the setHeader() method):
public static String getLookupResponse() {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://toolkit.dnb.com/access/scripts/broker.asp');
req.setMethod('POST');
req.setTimeout(60000);
req.setBody(m_lookupTemplate);
HttpResponse res = h.send(req);
return res.getBody();
}
where m_lookupTemplate is like the following (which works in their test harness HTML page):
<?xml version='1.0' encoding='UTF-8' ?>
<DGX>
<SIGNONMSGSRQV1>
<SONRQ>
<DTCLIENT>2009-04-04 10:49:28</DTCLIENT>
<USERID>craigmiled</USERID>
<USERPASS>XXXXXXXXX</USERPASS>
<LANGUAGE>EN</LANGUAGE>
<FI>
<ORG>DUN and BRADSTREET</ORG>
</FI>
<APPID>XML dnbToolkit</APPID>
<APPVER>0010</APPVER>
</SONRQ>
</SIGNONMSGSRQV1>
<CREDITMSGSRQV2>
<LOOKUPTRNRQ>
<TRNUID>242DF2924CC46</TRNUID>
<LOOKUPRQ>
<CTRY_CD>US</CTRY_CD>
<PRIM_NME>Caterpillar</PRIM_NME>
<TLCM_NBR></TLCM_NBR>
<ADR_LINE></ADR_LINE>
<NON_POST_TOWN></NON_POST_TOWN>
<POST_TOWN></POST_TOWN>
<PRIM_GEO_AREA>IL</PRIM_GEO_AREA>
<POST_CODE></POST_CODE>
<DUNS_NBR></DUNS_NBR>
<REGN_NBR></REGN_NBR>
<FILE_ID></FILE_ID>
<RTN_MAX></RTN_MAX>
<PURC_REAS_CD></PURC_REAS_CD>
<MTCH_TYPE></MTCH_TYPE>
</LOOKUPRQ>
</LOOKUPTRNRQ>
</CREDITMSGSRQV2>
</DGX>
This does not work as the server returns an "invalid request" result.
I tried setHeader('request',m_lookupTemplate) on HttpRequest instead of setBody(). No luck. The basic problem is that HttpRequest does not allow you to programatically set request parameters. Any ideas?
Thanks!
Dave
All Answers
I don't have a for-sure answer for you - it looks like you're on the right track. I just did a google search for "HTTP POST parameters" and came up to this page:
http://developers.sun.com/mobility/midp/ttips/HTTPPost/
It does show that the "body" of the request would be the URL-encoded name/value pairs of the request parameters. Two things occur to me:
1. I don't see the "request=" in the first part of the body
2. is the XML returned from the template URL-encoded?
Lastly, I don't know of a good way to debug the final output, but perhaps send the HttpRequest.getBody() results to the debug log to see if it's coming back the way you want. You might also try using the static results of that call in another call to the service using Java to see if the service will accept your data...
Good luck.
Thanks Simon and Ryan! I'll give that a shot and let you know.
Dave
You guys are geniuses! I replaced:
req.setBody(XML Mess)
with:
req.setBody('request=' + URL Encoded XML Mess)
and it worked.
Dave