Sto cercando di creare un nuovo utente Square, ma sto avendo problemi. Sono stato in grado di utilizzare Unirest per ottenere un elenco di clienti Square presso https://connect.squareup.com/v2/customers
punto finale, ma non è stato in grado di effettuare il POST con successo.
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);
});
La risposta ritorna
raw_body:
"{"errors":[{
"category":"INVALID_REQUEST_ERROR",
"code":"BAD_REQUEST",
"detail":"invalid character "e" looking for beginning of value (line 1, character 1)"}]}" }
Ho provato anche a usare .field
invece di .send
, che è tornato
raw_body: "{"errors":
[{"category":"INVALID_REQUEST_ERROR",
"code":"BAD_REQUEST",
"detail":"invalid character "-" in numeric literal (line 1, character 2)"}]}" }
È possibile creare un cliente utilizzando Unirest e Node? Se sì, dove sto andando male?
risposte:
0 per risposta № 1Il seguente codice sarà 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);
});