Saviez-vous Bot Libre propose gratuitement hébergé numéro de suivi pour votre propre site web ou une application mobile?
SDK and Web API

JSON web API

par pavelk posté 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: 2222, today: 1, week: 8, month: 15

by pavelk posted Oct 26 2018, 7:07

It works, thanks a lot!


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 2215, today: 6, week: 10, month: 17

Id: 24737015
Tags: api, javascript, json
Posté: Oct 24 2018, 12:05
Réponses: 2
Vues: 2298, aujourd'hui: 5, semaine: 9, mois: 14
0 0 0.0/5