MiguelMedeiros / lnbits-js

NPM Package for LNBits.com API.
23 stars 14 forks source link

Transactions Function Returns Nothing #2

Closed lylepratt closed 2 years ago

lylepratt commented 2 years ago

Howdy!

I was just testing out the userManager.getTransactions function, but it appears to return nothing because the API response for the endpoint that the function hits always returns nothing. I took a look at what endpoint the LNBits dashboard appears to use, and it looks like it uses api/v1/payments with the user's InvoiceRead Key passed as the x-api-key parameter.

Here is a CURL example that returns results:

curl -X GET https://legend.lnbits.com/api/v1/payments -H "X-Api-Key: {{User's Read Key}}"
MiguelMedeiros commented 2 years ago

I will make a patch with a fix for that! Thanks for reporting!

lylepratt commented 2 years ago

Cool! Let me know if I can do anything to help. 🍻

MiguelMedeiros commented 2 years ago

Hey @lylepratt I've tested the npm module and got the right result. The only thing that I had to change was the endpoint: 'https://legend.lnbits.com'

Check this out:

Get your credentials, don't forget the adminKey: image

Then you can get your user wallet id: image

Here is the code for it:

import LNBits from '../src/index';

const init = async () => {
  // Config
  const { userManager } = LNBits({
    adminKey: 'e1be6220afc7431f8c3c8bbe6c61b40e',
    invoiceReadKey: 'fa94a6672e63434f80d3a164feca0534',
    endpoint: 'https://legend.lnbits.com',
  });

  const tx = await userManager.getTransactions({
    wallet_id: 'd0043952cc7c47a89eeaaea654350015',
  });
  console.log(tx);

};
init();