During a conversation with one of our partners, he mentioned, “It’s a pity Latenode doesn’t have its own API yet, so we could automatically get data on our credit balance.”
Why is this important?
When automations run many operations, it becomes crucial to keep an eye on your credit balance, especially if you’re managing dozens of client accounts.
Sure, there’s an auto-renewal feature that kicks in when your balance drops below 5%, but having reports is still important!
That’s why, if the application doesn’t offer an API, a headless browser can come to the rescue—and that’s exactly what we’ll use here.
So let’s dive in! We’ll create a simple scenario (as shown in the image below):
Here’s how it works:
- Trigger on run once helps us with testing.
- Trigger on schedule allows you to set up the scenario to run according to your preferred schedule.
- Set variables stores your login credentials.
- And the Headless Browser will take care of the rest of the process.
To start, create two fields in the Set Variables node: one for your email and one for your password. Fill them in with your credentials. Once saved, move on to the next step.
In the Headless Browser node, just paste the provided code (make sure the node number matches your Set Variables number, which in my case is 9).
// Navigate to the required page
await page.goto('https://app.latenode.com/auth');
// Enter email
await page.type('[name="email"]', data["{{$9.email}}"]);
// Click the button
await page.click('.ant-btn.ant-btn-primary.ant-btn-block.button_N1qDU');
// Wait for the password field to appear
await page.waitForSelector('#password', { timeout: 5000 });
// Enter password
await page.type('#password', data["{{$9.password}}"]);
// Click the button
await page.click('.ant-btn.ant-btn-primary.ant-btn-block.button_N1qDU');
// Wait for the new page to load after login
await page.waitForNavigation({ waitUntil: 'networkidle0' });
// Check the URL after attempting to log in
const currentUrl = await page.url();
// Check login success based on the correct URL
let loginStatus;
if (currentUrl.includes('scenarios')) {
loginStatus = "success";
// Navigate to the statistics page
await page.goto('https://app.latenode.com/statistic');
// Wait for the element with selector .count_zLujN to load
await page.waitForSelector('.count_zLujN', { timeout: 5000 });
// Get text from the .count_zLujN selector
const countValue = await page.$eval('.count_zLujN', el => el.innerText);
// Return the result in JSON format
return {
status: loginStatus,
currentUrl: currentUrl,
countValue: countValue
};
} else {
loginStatus = "failed";
// Return the result in JSON format
return {
status: loginStatus,
currentUrl: currentUrl
};
}
(I added a couple of extra checks during the development process.)
Test it out, and everything should work! Then you can send the data wherever you prefer—whether it’s Slack, Telegram, or email.
Feel free to use this! I hope it helps someone else as well