首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从meteorjs访问osTicket接口?

如何从meteorjs访问osTicket接口?
EN

Stack Overflow用户
提问于 2015-11-16 14:39:16
回答 1查看 275关注 0票数 1

我一直在尝试从我的meteor代码访问osTicket应用程序接口,到目前为止我的代码如下:

代码语言:javascript
复制
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了解更多信息。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-11-16 17:05:27

使用fibers/future npm包。

添加 package meteor

代码语言:javascript
复制
meteor add http
meteor add meteorhacks:npm

创建packages.json并添加光纤

代码语言:javascript
复制
{
  "fibers": "1.0.7",
}

请参见:

代码语言:javascript
复制
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);
      });
    }
  })
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33729707

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档