I just signed up and was trying to get an access token but I keep getting an error. This is my code. Please ignore properties as they are built in features on my app. Can anyone suggest a fix here?
function(properties, context) {
var username = properties.client_id;
var password = properties.client_secret;
var auth = 'Basic' + Buffer.from(username + ':' + password).toString('base64');
let post = {
uri: `https://${properties.environment.toLowerCase()}.dwolla.com/token`,
method: 'POST',
header:{
"Content-Type": "application/json",
"Authorization" : auth
},
body:{
"client_id": properties.client_id,
"client_secret": properties.client_secret,
"grant_type": properties.grant_type
},
json: true
};
let result = context.request(post);
return {
full_body: JSON.stringify(result.body)};
}
spencer
(Spencer Hunter - Lead Developer Advocate @ Dwolla)
2
Hi @nocodeventure , It could be the body that is throwing off this request. I’d try removing the client_id and client_secret from the body and see if it works okay. Also, we do have a Node SDK that handles this specific request! Unless you’re wanting to leverage your own HTTP library. Here’s another example using axios that fetches a token and calls the root of the API you can maybe use as a reference: