【问题标题】:Google app api with freshdesk api error带有freshdesk api错误的G​​oogle app api
【发布时间】:2018-02-08 05:48:13
【问题描述】:

在使用来自谷歌应用脚​​本的 Freshdesk api 时遇到错误

"{"code":"invalid_content_type","message":"Content-Type header is set to . It should be set to application/json"}"

用于此的代码

function hd_getTickets(){//using v2
    var API_KEY = 'xxxxxxxxxxxxxx';
    var headers = {'Content-type': 'application/json','Authorization': 'Basic ' + Utilities.base64Encode(API_KEY + ':X')    };
    var data = {  "query":"\"priority:3\"" };
    var ENDPOINT = 'https://xxxxxxx.freshdesk.com/api/v2'; 
    var url = ENDPOINT + '/search/tickets';  
    var options = {      'method': 'get', muteHttpExceptions: true,'headers': headers,'payload' : JSON.stringify(data)};
    var response = UrlFetchApp.fetch(url, options);
}

更改端点并从选项中删除有效负载,因此假设授权和标头很好

var url = ENDPOINT + '/tickets';  
var options = {'method':'get','headers':headers, muteHttpExceptions: true};

使用邮递员这工作

https://xxxxxxx.freshdesk.com/api/v2/search/tickets?query="priority:3"

标头设置为

Content-Type:application/json
Authorization:Basic xxxxxxxxxxxxxxxx

【问题讨论】:

    标签: api google-apps-script freshdesk


    【解决方案1】:

    您正在通过选项中的 Payload 变量向 API 发送 GET 请求。 在我看来,有效载荷用于 POST 请求。

    使用查询参数构造 URL 并在没有 Payload 的情况下发送。 示例:'https://domain.freshdesk.com/api/v2/search/tickets?query="priority:3"'

    在此处查看详细信息:HTTP GET with request body Freshdesk API 文档:https://developers.freshdesk.com/api/#filter_tickets

    【讨论】:

    【解决方案2】:

    发现两个问题 1) 网站不支持基于payload的get。 2) google 应用不支持 url 中的特殊字符。

    将参数添加到原始网址并编码双引号。

      var ENDPOINT = 'https://xxxxxx.freshdesk.com/api/v2';   
      var query ='query='+encodeURIComponent("\"priority")+":1"+encodeURIComponent("\"");
      var url = ENDPOINT + '/search/tickets?'+query;  
      var options = {'method': 'get', muteHttpExceptions: true,'headers': headers}; 
      var response = UrlFetchApp.fetch(url, options);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多