So here is the function where I get the OAUTH2 Token from the Quickbooks server:
app.get('/callback', function (req, res) {
oauthClient
.createToken(req.url)
.then(function (authResponse) {
oauth2_token_json = JSON.stringify(authResponse.getJson(), null, 2);
console.log("Token:", oauth2_token_json)
newToken = oauth2_token_json;
oauthClient.setToken(newToken);
res.send(newToken);
})
});
Now, this is where I call the API to push a new Customer but it responds with status code 400. This is a function of Quickbooks library where we call the API directly just by adding the body and a call back function. I've also set the parameters as you can see in the code
.then(
qbo = new QuickBooks('ABReS9hFdUzNlD8Np17ufW8WU5xLyL0M0rv3HvekbXJdZUiWzi',
'Uy9NXu2fKmumP3JoCrxKxKugzLkdHhi8Ca00GSBz',
`${newToken}`,
false, // no token secret for oAuth 2.0
'4620816365092507370', // the company name or id provided by Quickbooks
true, // use the sandbox?
true, // enable debugging?
null, // set minorversion, or null for the latest version
'2.0', //oAuth version
null)
.createCustomer({
"FullyQualifiedName": "King Groceries",
"PrimaryEmailAddr": {
"Address": "jdrew@myemail.com"
},
"DisplayName": "King's Groceries",
"Suffix": "Jr",
"Title": "Mr",
"MiddleName": "B",
"Notes": "Here are other details.",
"FamilyName": "King",
"PrimaryPhone": {
"FreeFormNumber": "(555) 555-5555"
},
"CompanyName": "King Groceries",
"BillAddr": {
"CountrySubDivisionCode": "CA",
"City": "Mountain View",
"PostalCode": "94042",
"Line1": "123 Main Street",
"Country": "USA"
},
"GivenName": "James"
}, function(err, customer){
console.log(customer)
})
)
When I make the request it hits the correct URL. The ClientID and ClientSecret are completely correct. I don't understand why am I getting this status code. I've changed the sandbox that I was using. I deleted the old sandbox and created a new one. Can anyone explain how can I fix this issue?