如何使用 Node.js 和 Unirest 创建 Square Customer

How to create Square Customer with Node.js and Unirest

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

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);
});

回复returns

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 创建客户?如果是这样,我哪里错了?

下面的代码会POST

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);
});