Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug/Feature]: Allow syncing to existing GoCardless requisitions #476

Open
1 task done
ftruzzi opened this issue Oct 8, 2024 · 1 comment
Open
1 task done

[Bug/Feature]: Allow syncing to existing GoCardless requisitions #476

ftruzzi opened this issue Oct 8, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ftruzzi
Copy link
Contributor

ftruzzi commented Oct 8, 2024

Verified issue does not already exist?

  • I have searched and found no existing issue

What happened?

Hi!

I am struggling to sync my bank account (Fineco, Italy) to Actual. I managed to do it once after many attempts, but then the connection broke and I'm experiencing the same issue. I noticed that every attempt increases the number of active connections on my GoCardless account and I'm getting close to the 50 limit since existing connections expire the following month even if manually deleted.

I will try to debug the issue more and hopefully provide more details (I still need to add my bank to those with limited history), but what I can say in the meanwhile is that the connection is successful on the GoCardless side and appears in the /api/v2/requisitions endpoint as successfully linked.

So I wonder if it would be possible for Actual to fetch and allow accounts from existing requisitions before trying to create a new one. I guess this would allow to retry linking in an easier and faster way if it fails on Actual side, and not eat up all the free connections on GoCardless if experiencing issues.

Thanks!

What error did you receive?

Linking fails with 409 Conflict from /gocardless/get-accounts, but account was linked correctly on GoCardless

See stack trace

 Error /gocardless/get-accounts ResourceSuspended [Error]: Resource was suspended due to numerous errors that occurred while accessing it
    at handleGoCardlessError (file:///app/src/app-gocardless/services/gocardless-service.js:53:13)
    at Object.getDetailedAccount (file:///app/src/app-gocardless/services/gocardless-service.js:414:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///app/src/app-gocardless/services/gocardless-service.js:153:25
    at async Promise.all (index 1)
    at async Object.getRequisitionWithAccounts (file:///app/src/app-gocardless/services/gocardless-service.js:151:30)
    at async file:///app/src/app-gocardless/app-gocardless.js:68:9 {
  details: h [AxiosError]: Request failed with status code 409
      at te (file:///app/node_modules/nordigen-node/dist/index.esm.js:13:914)
      at IncomingMessage.<anonymous> (file:///app/node_modules/nordigen-node/dist/index.esm.js:17:16315)
      at IncomingMessage.emit (node:events:529:35)
      at endReadableNT (node:internal/streams/readable:1400:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ERR_BAD_REQUEST',
    [...]
    response: {
      status: 409,
      statusText: 'Conflict',
      headers: [T [AxiosHeaders]],
      config: [Object],
      request: [ClientRequest],
      data: [Object]
    }

Where are you hosting Actual?

Docker

What browsers are you seeing the problem on?

No response

Operating System

Linux

@ftruzzi ftruzzi added the bug Something isn't working label Oct 8, 2024
@fira42073
Copy link

This is a workaround I'm using:

First running the script without GOCARDLESS_MODE to read all active requisitions, and then GOCARDLESS_MODE=DELETE to remove all of them.

# pip install nordigen
import json
import os

from nordigen import NordigenClient

# initialize Nordigen client and pass SECRET_ID and SECRET_KEY
client = NordigenClient(
    secret_id=os.environ["GOCARDLESS_SECRET_ID"],
    secret_key=os.environ["GOCARDLESS_SECRET_KEY"],
)

# mode is either READ or DELETE
MODE = os.environ.get("GOCARDLESS_MODE", "READ").upper()
if MODE not in ["READ", "DELETE"]:
    raise ValueError(f"Invalid MODE: {MODE}. It should be 'READ' or 'DELETE'.")

# Create new access and refresh token
# Parameters can be loaded from .env or passed as a string
# Note: access_token is automatically injected to other requests
# after you successfully obtain it
token_data = client.generate_token()

# # Use existing token
# client.token = "YOUR_TOKEN"
#
# # Exchange refresh token for new access token
# new_token = client.exchange_token(token_data["refresh"])

if MODE == "READ":
    # Get institution id by bank name and country
    requisitions = client.requisition.get_requisitions()

    todump = []

    for requisition in requisitions["results"]:
        todump.append(
            {
                "id": requisition["id"],
                "institution_id": requisition["institution_id"],
                "link": requisition["link"],
            }
        )
        print(f"Requisition ID: {requisition['id']}")

    with open("requisitions.json", "w") as f:
        f.write(json.dumps(todump, indent=4))

elif MODE == "DELETE":
    with open("requisitions.json", "r") as f:
        requisitions = json.loads(f.read())

    for requisition in requisitions:
        client.requisition.delete_requisition(requisition_id=requisition["id"])
        print(f"Deleted requisition {requisition['id']}")

    os.remove("requisitions.json")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants