【问题标题】:How to create Square Customer with Node.js and Unirest如何使用 Node.js 和 Unirest 创建 Square Customer
【发布时间】:2017-04-19 02:30:13
【问题描述】:

我正在尝试创建一个新的 Square 用户,但遇到了问题。我能够使用 Unirest 在 https://connect.squareup.com/v2/customers 端点获取 Square 客户列表,但无法成功发布。

const unirest = require('unirest');
const access_token = 'sq-123...';

var createCustomer = 
unirest.post('https://connect.squareup.com/v2/customers')
  .headers({
    "Accept": "application/json",
    "Authorization": "Bearer " + access_token})
  .send({
    "email_address": "abc@example.com"
  })
  .end(function (createCustomer) {
    console.log(createCustomer);
});

响应返回

raw_body: 
'{"errors":[{
"category":"INVALID_REQUEST_ERROR",
"code":"BAD_REQUEST",
"detail":"invalid character \'e\' looking for beginning of value (line 1, character 1)"}]}' }

我也尝试使用.field 而不是.send,它返回了

raw_body: '{"errors":
[{"category":"INVALID_REQUEST_ERROR",
"code":"BAD_REQUEST",
"detail":"invalid character \'-\' in numeric literal (line 1, character 2)"}]}' }

是否可以使用 Unirest 和 Node 创建客户?如果是这样,我哪里出错了?

【问题讨论】:

  • 尝试发送Content-Type: application/json标头让服务器知道数据是json类型。您也可以使用 unirest 的 type,例如unireset.post().headers().type('json').send..
  • 好的,使用.send 命令有效。谢谢!

标签: node.js square-connect unirest


【解决方案1】:

以下代码将发布

const unirest = require('unirest');
const access_token = 'sq-123...';

var createCustomer = 
unirest.post('https://connect.squareup.com/v2/customers')
  .headers({
    "Content-Type": "application/json",
    "Authorization": "Bearer " + access_token})
  .send({
    "email_address": "abc@example.com"
  })
  .end(function (createCustomer) {
    console.log(createCustomer);
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 2020-01-26
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    相关资源
    最近更新 更多