Scaricare l'open source Bot Libre Community Edition e installare Bot Libre nel proprio server
SDK and Web API

JSON web API

da pavelk postato Oct 24 2018, 12:05

Hello,

I'm trying to fetch a list of instances using JSON endpoint:

var request = new XMLHttpRequest();
request.open('POST', 'https://www.botlibre.com/rest/json/get-all-instances', true);
request.setRequestHeader('Content-Type', 'application/json');
var json = JSON.stringify({'application': '721375371321663745'});
request.onreadystatechange = function() {
console.log(request.responseText);
};
request.send(json);

However, I got the following response:

Missing application id. You can obtain an application id from your user page.

 

Am I doing something wrong? What is the correct way to pass an application id to this JSON endpoint?

The same request body format works fine with JSON "/rest/json/chat":

var request = new XMLHttpRequest();
request.open('POST', 'https://www.botlibre.com/rest/json/chat', true);
request.setRequestHeader('Content-Type', 'application/json');
var json = JSON.stringify({
"application": "721375371321663745",
"instance": "909409",
"message": "Hello"
});
request.onreadystatechange = function() {
console.log(request.responseText);
};
request.send(json);


by admin posted Oct 25 2018, 9:35

For the JSON API any attribute (from the XML API) requires an @ prefix (except for the /chat API).

i.e.

var request = new XMLHttpRequest();
request.open('POST', 'https://www.botlibre.com/rest/json/get-all-instances', true);
request.setRequestHeader('Content-Type', 'application/json');
var json = JSON.stringify({'@application': '721375371321663745'});
request.onreadystatechange = function() {
console.log(request.responseText);
};
request.send(json);

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 2217, today: 3, week: 3, month: 10

by pavelk posted Oct 26 2018, 7:07

It works, thanks a lot!


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 2207, today: 2, week: 2, month: 9

Id: 24737015
Tag: api, javascript, json
Postato: Oct 24 2018, 12:05
Risposte: 2
Vista: 2290, oggi: 1, settimana: 1, mese: 6
0 0 0.0/5