Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUTTER_CLIENT_ID=
RUTTER_SECRET=
# Use 'sandbox' to test with fake credentials in the Sandbox environment
# Use 'production' to go live with real users. To get access to production, visit your dashboard https://dashboard.rutterapi.com
RUTTER_URL=sandbox.rutterapi.com
RUTTER_URL=

# FRONTEND VARIABLES
# NEXTJS requires NEXT_PUBLIC prefix to expose environment variables to the front-end
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"dependencies": {
"axios": "^0.21.0",
"bootstrap": "^4.6.0",
"next": "10.0.3",
"react": "17.0.1",
"next": "^15.3.1",
"postcss": "^8.5.3",
"postcss-scss": "^4.0.9",
"react": "^19.1.0",
"react-bootstrap": "^1.4.3",
"react-dom": "17.0.1",
"react-dom": "^19.1.0",
"react-rutter-link": "^1.0.1"
}
}
52 changes: 52 additions & 0 deletions pages/api/rutter-list-account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import axios from "axios";

const ENV_URL = process.env.RUTTER_URL || "sandbox.rutterapi.com";
const CLIENT_ID = process.env.RUTTER_CLIENT_ID || "RUTTER_CLIENT_ID";
const SECRET = process.env.RUTTER_SECRET || "RUTTER_SECRET";

// handles exchanging the token and calling a sample API route
export default async (req, res) => {
if (req.method === "POST") {
// Process a POST request
const { accessToken } = req.body;

// Exchange publictoken for access_token
try {
const response = await axios.get(`https://${ENV_URL}/versioned/accounting/accounts

`, {
params: {
access_token: accessToken,
},
auth: {
username: CLIENT_ID,
password: SECRET,
},
headers: {

"X-Rutter-Version": "2024-08-31"

}

});
const {
data: { accounts },
} = response;
// Respond with the access-token
res.statusCode = 200;
res.json({
accounts,
});
} catch (e) {
console.error(e.response.data);
res.status(500).json({
error: e.message,
});
}
} else {
// Handle any other HTTP method
res.statusCode(401).json({
error_message: "Unauthorized Method",
});
}
};
28 changes: 28 additions & 0 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ async function fetchCustomers(accessToken) {
return result;
}


async function getListofAccounts(accessToken) {
const result = await axios.post("/api/rutter-list-account", {
accessToken,
});
return result;
}

export default function Home() {
const [dataFetched, setDataFetched] = React.useState(null);
const [loading, setLoading] = React.useState(false);
Expand Down Expand Up @@ -101,6 +109,19 @@ export default function Home() {
}
};

const handleGetListofAccounts = async () => {
setDataFetched(null);
setLoading(true);
try {
const accounts = await getListofAccounts(accessToken);
setDataFetched(accounts);
} catch (e) {
setErrorMessage(e.message);
} finally {
setLoading(false);
}
};

if (loading && !rutterConnected) {
return (
<div>
Expand Down Expand Up @@ -145,6 +166,13 @@ export default function Home() {
<Button onClick={handleGetCustomers}>Send request</Button>
</td>
</tr>
<tr>
<td>GET</td>
<td>/accounts</td>
<td>
<Button onClick={handleGetListofAccounts}>Send request</Button>
</td>
</tr>
</tbody>
</Table>
{loading && (
Expand Down
Loading