【发布时间】:2019-04-24 17:05:25
【问题描述】:
我的目标是导出我使用 Google Apps 脚本对 Qualtrics 进行的一项调查的回复。我试图让我的代码使用 POST API,并且我得到了 ping 代码,但是无论它在 ping 什么,它都会返回一个“httpStatus:400-Bad request”错误。
我对 Google Apps 脚本和 API 都不熟悉,但了解它的要点。我使用 Postman 获取了一个 javaScript Jquery ajax 代码,并使其与 GAS 一起工作。让我感到困惑的是,当我将相同的代码与 GET API 一起使用并手动输入 ID(使用 POSTMAN 提供给我)时,它会完美地 ping。通过 Postman 运行它时,它表明一切都在进行,所以不确定我在 POST 调用中做错了什么。
var option = {
async: true,
crossDomain: true,
//url:"https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_8dK8AKUFyAH8qyN//export-responses/",
method: "POST",
"headers": {
"X-API-TOKEN": "**************************",
"Content-Type": "application/json",
"cache-control": "no-cache",
"Postman-Token": "7a148b75-fa03-4f45-9782-08791c2f1c35"
},
processData: false,
data : '{"format": "csv}',
muteHttpExceptions: true //muted to check Logger
};
var qUrl='https://ousurvey.ca1.qualtrics.com/API/v3/surveys/SV_8dK8AKUFyAH8qyN/export-responses/'
var getSurvey = UrlFetchApp.fetch(qUrl, option);
我需要让 POST 工作以获取 JSON 以获取调查 ID,以便我可以使用该 ID 和 GET API 将信息下载到谷歌驱动器并将信息转换为 GoogleDocs。
这是日志中的当前错误:
{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Error decoding json body:
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input\n at
[Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1@71f9c2bb; line: 1, column: 0]"}}}
将“Content-Type”更改为“contentType”后出现此错误:
""meta":{"requestId":"62b3a313-b1ba-4939-83b7-ee73e65b4e3e","httpStatus":"400
- Bad Request","error":{"errorCode":"QVAL_1","errorMessage":"Json type request body is expected.""
【问题讨论】:
-
您的数据可能只是一个对象,即
{ "format" : "csv" },而不是字符串。 -
不走运,我试过这样做,但仍然发出错误的请求
-
你有错误信息/代码吗?像“预期_但得到_”之类的东西?
-
我用收到的错误消息更新了帖子,并更改了数据格式。
-
能否提供API的文档?我认为这些信息可能对你有用。 developers.google.com/apps-script/reference/url-fetch/… 但如果这没有用,我很抱歉。
标签: javascript api post google-apps-script qualtrics