我一直在尝试从我的meteor代码访问osTicket应用程序接口,到目前为止我的代码如下:
if (Meteor.isServer) {
Meteor.methods({
osTicket: function() {
this.unblock();
return HTTP.post("http://www.xxxxxxxx.com/uploads/api/tickets.json","X-API-Key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
{
data: {
"alert": true,
"autorespond": true,
"source": "API",
"name": "Angry",
"email": "api@osticket.com",
"phone": "3185558634X123",
"subject": "Testing API",
"ip": "172.22.78.114",
"message": "MESSAGE HERE",
"attachments": [{
"file.txt": "data:text/plain;charset=utf-8,content"
}, {
"image.png": "data:image/png;base64,R0lGODdhMAA..."
}, ]
},
},
function(error, results) {
if (results) {
console.log(results);
} else {
console.log(error)
}
}
);
}
});
}
if (Meteor.isClient) {
Template.api.events({
'click #submitQuery': function() {
Meteor.call("osTicket");
}
})
}我从api得到一个200状态和一些html代码,这意味着连接成功,但我无法使用api从我的代码创建任何票证。
那么,我做错了什么呢?我用来连接api的语法正确吗?
请参考https://github.com/osTicket/osTicket-1.7/blob/develop/setup/doc/api/tickets.md了解更多信息。
谢谢。
发布于 2015-11-16 17:05:27
使用fibers/future npm包。
添加 package meteor
meteor add http
meteor add meteorhacks:npm创建packages.json并添加光纤
{
"fibers": "1.0.7",
}请参见:
if (Meteor.isServer) {
var Future = Meteor.npmRequire('fibers/future');
Meteor.methods({
osTicket: function() {
// Create our future instance.
var future = new Future();
data = {
"alert": true,
"autorespond": true,
"source": "API",
"name": "Angry",
"email": "api@osticket.com",
"phone": "3185558634X123",
"subject": "Testing API",
"ip": "172.22.78.114",
"message": "MESSAGE HERE",
"attachments": [
{ "file.txt": "data:text/plain;charset=utf-8,content" },
{ "image.png": "data:image/png;base64,R0lGODdhMAA..." },
]
};
return HTTP.post("http://www.xxxxxxxx.com/uploads/api/tickets.json","X-API-Key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", { data: data },
function(error, response) {
if (error) {
return future.return(error);
} else {
future.return( response );
}
});
return future.wait();
}
});
}
if (Meteor.isClient) {
Template.api.events({
'click #submitQuery': function() {
Meteor.call("osTicket", function(error, response) {
console.log(response);
});
}
})
}https://stackoverflow.com/questions/33729707
复制相似问题