【发布时间】:2022-02-07 00:57:04
【问题描述】:
我在 Google 脚本中有以下代码:
var data = {
"records": [
{
"fields": {
"Contract Address": "test",
"0x8df3aad3a84da6b69a4da8aec3ea40d9091b2ac4": "1234"
}
}
]
};
var options = {
"method" : "post",
'Content-Type': 'application/json',
'muteHttpExceptions' : true,
// "payload" : data,
"payload" : JSON.stringify(data)
};
function tryAPost(){
var url = "https://api.airtable.com/v0/xxxxxxxxxxxxx/Balance%20Tracking?api_key=keyxxxxxxxxxx";
var response = UrlFetchApp.fetch(url, options);
//console.log(response.getContentText());
console.log(response.getResponseCode());
};
我收到以下回复:
422
而且数据最终不会出现在 Airtable 中。
payload 在 Postman 中的 post 请求正文中工作。
我做错了什么?
根据评论编辑:
这是 airtable 中的示例代码:
var Airtable = require('airtable');
var base = new Airtable({apiKey: 'YOUR_API_KEY'}).base('xxxxxxxxxxxx');
base('Balance Tracking').create([
{
"fields": {
"Contract Address": "Thu, 03 Feb 2022 15:12:37 GMT",
"0xfecf784f48125ccb7d8855cdda7c5ed6b5024cb3": 12055358359168
【问题讨论】:
-
您需要向我们提供一些文档,因为 api 文档似乎并不公开。试试
"payload" : JSON.stringify(data) -
我将 airtable 中的示例代码添加到问题中。我试过
JSON.strigify(data),但没用。 -
这是 JSON.stringify(object)
-
你至少需要显示邮递员截图。此外,您应该将响应记录为文本:
console.log(response.getContentText()) -
@Cooper 很抱歉这么厚,但我认为
data是一个对象。
标签: api google-apps-script urlfetch airtable http-status-code-422