Post by Satish Jogi Post by Satish Jogi
I am trying to call one of the HTTP Client Connector in another Connector Add/Update Hooks. Kindly help me to provide some hints, so that i will try to complete.
Thanks, i have used the below script to call another connector.
var httpConn = system.getConnector("ibmdi.HTTPClient");
Nice, Satish. I do all my http work from script like you're doing now. Note that .initialize() works just as well with null passed as the argument. If you want the connector to be pre-configured then you create it in the Resources > Connectors folder and give the name in the getConnector() call. Easy as spitting.
Furthermore, I often set parameters based on properties, and sometimes via script:
Of course, if you use the CallReply mode function of the Connector Interface (which only a few Connectors implement) then you can pass in an Entry object when the call is made. This can contain attributes named appropriately:
request = system.newEntry();
request["http.body"] = toJson(someJSObject);
request["http.accept = "application/json";
request["http.content-type"] = "application/json";
request["http.method"] = "POST";
request["http.url"] = "https://...";
response = httpConn.queryReply(request); // queryReply() is the CallReply CI function
Then the call uses these attribute values. You have to use bracket-notation to specify these variables since they have special characters in the name. Otherwise you could standard dot-notation:
work.cn = "Roger Rabbit";
work.sn = "Rabbit";
And I never attach a Parser to the HTTP Connectors. I grab the http.bodyAsString attribute (always returned as a string, regardless of Content-Type specifier) and parse it myself. Let me know if you want any tips on this.