Hi,
I am trying to store some information on my backend when I create a user, the information is supposed to be the response from creating a customer, but I get undefined.
Here is my code.
import { json } from “express”;
//This class is used for creating customers on Dwolla.
var dwolla = require(‘dwolla-v2’);
var key = “0000”
var secret = “0000”
var client = new dwolla.Client({
// key: process.env.DWOLLA_APP_KEY,
key:key,
// secret: process.env.DWOLLA_APP_SECRET,
secret:secret,
environment: ‘sandbox’,
});
//RequestBody contains the information pertaining to the user.
var requestBody = {
firstName: firstName,
lastName: lastName,
email: email,
type: ‘personal’,
address1: address1,
city: city,
state: state,
postalCode: postalCode,
dateOfBirth: dateOfBirth,
// For the first attempt, only the
// last 4 digits of SSN required
// If the entire SSN is provided,
// it will still be accepted
ssn: ssn
};
asyncCall();
async function asyncCall() {
try {
client.auth.client()
.then(appToken => appToken.post(‘customers’, requestBody))
// .then.post(‘customers’, requestBody)
.then(res => res.headers.get(‘location’)) // => ‘https://api-sandbox.dwolla.com/customers/fc451a7a-ae30-4404-aB95-e3553fcd733f’
// .then(res => console.log(res.headers.get(‘location’)))
.then(async function(res) {
const result = await (JSON.stringify(res.body));
const result2 = await (JSON.stringify(res.headers));
console.log(result)
console.log(result2)
});
} catch (err) {
console.log(err)
console.log("Did not work");
}
// expected output: 'resolved'
}