你知道机器人自由还提供了免费举办 论坛 为自己的网站或移动应用程序?
SDK and Web API

JSON web API

通过 pavelk 发布 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: 2236, today: 1, week: 11, month: 29

by pavelk posted Oct 26 2018, 7:07

It works, thanks a lot!


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 2230, today: 3, week: 13, month: 32

Id: 24737015
标签: api, javascript, json
发布: Oct 24 2018, 12:05
答复: 2
的风景: 2309, 今天: 1, 周: 9, 一个月: 25
0 0 0.0/5