UPDATE 19 Feb 2016 - see below
I'm building an hybrid mobile app for proximity marketing (i.e. a mobile app which will interact with beacons), and I'd like to use the Bluemix Presence Insights Service to collect data. The problem is I cannot connect through SDK since it is an hybrid app therefore I need to use the connectors API. I've made some attempts and I still get the 401 response.
I've tried an Ajax call setting the Basic Autentication Headers:
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
},
or
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic <my encrypted token>");
},
or
headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},
(also with the encrypted token, I'm not rewriting it).
Then I've made a Node.js server and installed swagger-client (i.e. I've changed strategy):
router.post('/', function (req, res, next) {
var json = req.body.json;
var client = new Swagger({
url: 'https://presenceinsights.ibmcloud.com/pi-swagger/the-connector-api',
success: function () {
console.log("success");
console.log(JSON.stringify(client));
},
authorizations : {
easyapi_basic: new Swagger.PasswordAuthorization('username', 'password')
}
});
res.end();
});
This time I've made progress:
I can successfully connect but I'm not able to send the JSON with the data. Having not access to swagger.json
how do I declare the body of the post request? Is there any way to get access to swagger.json
of presence insights (this thing will solve all my problems)?
UPDATE After an exchange of information with Presence Insights support I can say it is not viable to call the Swagger client. The only way to use the service with an hybrid app, it is building a proxy Blumix runtime which it will forward the datas from the hybrid application to the Presence Insights service. Any other attempt, either with an external server or by calling the API within the application is not permitted, as CORS policy doesn't allow it. This is true for connectors AND management.
I'm writing this for future reference.