Just an update on this ... one of my colleagues ( tuttinator ) has managed to get the new javascript platform client working through a proxy by making some changes, so listing here in case anymore else is in need.
We are using Node.Js for our queries.
The main changes are that in node_modules/purecloud-platform-client-v2/src/purecloud-platform-client-v2/ApiClient.js they added two convenience functions:
/* Request mutator */
exports.prototype.setProxy = function(wrapperFunc, proxyUrl) {
console.log("setProxy called...")
console.info(this);
this._proxyRequests = true;
this._proxyWrapperFunc = wrapperFunc;
this._proxyUrl = proxyUrl || process.env.http_proxy;
};
exports.prototype.unsetProxy = function() {
this._proxyRequests = undefined;
this._proxyWrapperFunc = undefined;
this._proxyUrl = undefined;
};
And then in the callApi and loginClientCredentialsGrant methods, they add a pattern of using wrapper function as the superagent-proxy documentation seemed to indicate:
β¦
exports.prototype.callApi = function callApi(path, httpMethod, pathParams,
queryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts) {
var _this = this;
var url = this.buildUrl(path, pathParams);
var requestHandler;
if(this._proxyRequests == true) {
console.log("Proxying through ", this._proxyUrl);
requestHandler = this._proxyWrapperFunc(superagent);
} else {
requestHandler = superagent;
}
var request = requestHandler(httpMethod, url);
β¦
if(this._proxyRequests == true) {
request.proxy(this._proxyUrl)
}
β¦
};
We were testing using a basic authentication request ... to get that working there were some additions at the very top :
const platformClient = require('purecloud-platform-client-v2');
const superagentProxy = require('superagent-proxy');
var client = platformClient.ApiClient.instance;
//client.setReturnExtendedResponses(true);
client.setEnvironment('mypurecloud.com.au');
client.setProxy(superagentProxy, 'http://yourproxyhere.com:80');
The changes have been saved as a fork in the code here - https://github.com/tuttinator/platform-client-sdk-javascript .
He also noted a possible error in the following documentation (https://developer.mypurecloud.com/api/rest/client-libraries/javascript/index.html ... Making Requests ... Node.js) :
.catch(function(response) {
// Handle failure response
console.log(`${response.status} - ${response.error.message}`);
console.log(response.error);
});
"That catch block receives a flat object which doesnβt have a status, error, or error.message property (which was that error you saw) β at least in the case of a proxy error."