admin管理员组文章数量:1134744
I am having trouble setting up my function to get my auth tokens from quickbooks using the auth code.
cors(req, res, async () => {
const clientId = functions.config().quickbooks.client_id;
const clientSecret = functions.config().quickbooks.client_secret;
const redirectUri = functions.config().quickbooks.redirect_uri;
const basicAuth = require('btoa')(clientId + ':' + clientSecret)
const { code } = req.body;
if (!code) {
return res.status(400).send({ error: 'Authorization code is required' });
}
// Prepare the request body (URL encoded)
const requestBody = new URLSearchParams({
grant_type: 'authorization_code',
code: code,
redirect_uri: redirectUri,
}).toString();
try {
const response = await fetch('', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${basicAuth}`,
'Accept': 'application/json',
},
body: requestBody,
});
// Check if response is OK, else log the error
if (!response.ok) {
const errorDetails = await response.text(); // Capture non-JSON response
console.error("QuickBooks API Error:", errorDetails);
return res.status(500).send({ error: 'Error authenticating with QuickBooks', details: errorDetails });
}
const data = await response.json();
return res.status(200).send({ success: true, data: data });
} catch (error) {
console.error("Error in exchangeAuthCodeForTokens function:", error.message);
return res.status(500).send({ error: error.message });
}
});
I am always getting status 500 (Internal Server Error)
I have console-logged all variables, and they match, with no other errors found.
What could I be doing here that could cause the issues at hand? Any help would be great, thanks!
I am having trouble setting up my function to get my auth tokens from quickbooks using the auth code.
cors(req, res, async () => {
const clientId = functions.config().quickbooks.client_id;
const clientSecret = functions.config().quickbooks.client_secret;
const redirectUri = functions.config().quickbooks.redirect_uri;
const basicAuth = require('btoa')(clientId + ':' + clientSecret)
const { code } = req.body;
if (!code) {
return res.status(400).send({ error: 'Authorization code is required' });
}
// Prepare the request body (URL encoded)
const requestBody = new URLSearchParams({
grant_type: 'authorization_code',
code: code,
redirect_uri: redirectUri,
}).toString();
try {
const response = await fetch('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${basicAuth}`,
'Accept': 'application/json',
},
body: requestBody,
});
// Check if response is OK, else log the error
if (!response.ok) {
const errorDetails = await response.text(); // Capture non-JSON response
console.error("QuickBooks API Error:", errorDetails);
return res.status(500).send({ error: 'Error authenticating with QuickBooks', details: errorDetails });
}
const data = await response.json();
return res.status(200).send({ success: true, data: data });
} catch (error) {
console.error("Error in exchangeAuthCodeForTokens function:", error.message);
return res.status(500).send({ error: error.message });
}
});
I am always getting status 500 (Internal Server Error)
I have console-logged all variables, and they match, with no other errors found.
What could I be doing here that could cause the issues at hand? Any help would be great, thanks!
Share Improve this question asked Jan 7 at 21:23 Stevan NajeebStevan Najeeb 1092 silver badges13 bronze badges1 Answer
Reset to default 0Sometimes, the issue might be on QuickBooks' side. You could check the QuickBooks Developer API status page or look for any updates in forums to see if there are any ongoing problems with their OAuth service.
If you've already checked the variables and the request format, try adding more detailed logging. Focus on logging the full response from QuickBooks, as it might give you more information about the error and help you figure out what’s going wrong.
本文标签: nodejsQuickBooks oAuth2 Get Tokens With Auth Code (NodeJs)Stack Overflow
版权声明:本文标题:node.js - QuickBooks oAuth2 Get Tokens With Auth Code (NodeJs) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736774241a1952251.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论