0

我正在与Sheetlabs合作将 Google Sheet 转换为完整的 API。除了 Sheetlabs文档之外,我在网上找不到有用的信息时遇到了麻烦,因为此时它似乎是一项相当小的服务。

我在 Twilio 的自定义函数中使用 axios 将信息发布到我们的 Sheetlabs API。API 需要 HTTP 基本身份验证。

我在我的 axios 调用上尝试了各种变体,试图遵循Sheetlabs SwaggerHub 文档,但我的想法已经不多了。

const url = 'https://sheetlabs.com/records/{organization}/{dbName}';

const postData = {
  trackingid: `${trackingUrl}`,
  phonenumber: `${userPhoneNumber}`
}

const authParams = {
  username: //sheetlabs email,
  password: //access token
}

// axios function
axios.post(url, postData, {auth: authParams}).then(response => {
  console.log('response: ', response);
}).catch(err => {
  console.log('axios sheetlabs post error catch: ', err);
});

任何帮助将不胜感激。我会尽力为您提供您需要的任何其他信息。

4

2 回答 2

0

AJAX 默认以application/x-www-form-urlencoded格式发送数据,但 Axios 以 JSON 格式发送。我提到 AJAX 是因为在示例页面中他们$.ajax用于执行网络请求。

Axios 在他们的 Github 上提到了这个默认值这是我在许多没有发送接收 JSON 的服务器上遇到的。npm install qs尝试做一个并看看它是否对您有帮助可能值得一试:

const qs = require('qs');
axios.post(url, qs.stringify(postData), {auth: authParams}).then(response => {
  console.log('response: ', response);
}).catch(err => {
  console.log('axios sheetlabs post error catch: ', err);
});
于 2019-01-05T02:26:35.313 回答
0

我联系了 Sheetlabs 支持,目前他们不支持通过帖子向 Google 表格添加新记录。我可以发誓我在他们的文档和 API 中看到了这种能力。谢谢你的回复。

于 2019-01-05T21:37:35.117 回答