jhonderson / actual-http-api

Basic Actual Budget API exposed through HTTP endpoints
MIT License
43 stars 13 forks source link

Failed to fetch #7

Closed gerardsyd closed 9 months ago

gerardsyd commented 9 months ago

Hi - thanks for this. I'm trying to access via the webUI and keep getting this error:

Failed to fetch.
Possible Reasons:

CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.

I'm not entirely sure what it means and not familiar with node to try and debug. Nothing is showing up in the docker logs so can't see where it's failing.

Here is my actual set up and the set up for actual-http-api. Both are set up in docker containers:

  # Actual: Budgeting App
  actual:
    image: actualbudget/actual-server:latest
    container_name: actual
    networks:
      - t2_proxy
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
    logging:
      options:
        max-size: "10m"
        max-file: "5"
    ports:
      - '5006:5006'
    environment:
       TZ: $TZ
       PUID: $PUID
       PGID: $PGID
    volumes:
      - ${DOCKERDIR}/shared/actual:/data
    labels:
      - "traefik.enable=true"
      ## HTTP Routers
      - "traefik.http.routers.actual-rtr.entrypoints=https"
      - "traefik.http.routers.actual-rtr.rule=Host(`actual.$DOMAINNAME`)"
      ## Middlewares
      - "traefik.http.routers.actual-rtr.middlewares=chain-oauth@file"
      ## HTTP Services
      - "traefik.http.routers.actual-rtr.service=actual-svc"
      - "traefik.http.services.actual-svc.loadbalancer.server.port=5006"

  # Actual API Access
  actualapi:
    container_name: actualapi
    image: jhonderson/actual-http-api:latest
    networks:
      - t2_proxy
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
    logging:
      options:
        max-size: "10m"
        max-file: "5"
    volumes:
      - ${DOCKERDIR}/shared/actualapi/data:/data:rw
    ports:
      - '5007:5007'
    environment:
       TZ: $TZ
       PUID: $PUID
       PGID: $PGID
      ACTUAL_SERVER_URL: ${ACTUAL_SERVER_URL}
      ACTUAL_SERVER_PASSWORD: ${ACTUAL_SERVER_PASSWORD}
      API_KEY: ${ACTUAL_API_KEY}

The ACTUAL_SERVER_URL is set to my external url -> https://actual.DOMAINNAME

On the UI, I've tried both connecting to localhost as well as the {domainname} version but neither appears to work.

Not sure if I need to set up the traefik access or whether I need them on the same server or if ACTUAL_SERVER_URL needs to point to the local IP address (which is problematic with the SSL certs).

Any assistance would be appreciated. Thank you.

EDIT: I should note that Actual sits behind traefik which is using google oauth in front of the password protection. Not sure if that could also be the issue.

jhonderson commented 9 months ago

Hello, I will share a bunch of information here, let me know if anything helps.

  1. This looks like a CORS configuration issue in your actual server, likely in traefik. You can try researching how to enable cors in traefik, or you can take advantage of the fact that both containers are in the same network and just use something like http://actual:5006/ for ACTUAL_SERVER_URL. I would prefer the former in case you want to deploy both containers separately in the future.
  2. Since you likely want to access your actual api externally, I would also configure a public endpoint for this container. This may help with the CORS issue since they both would be sharing the same base domain (not 100% sure)
  3. In the swagger UI, make sure that the host you configure is the one for the actual api, not the actual server.

if none of the above helps, please past your curl command (should be available through Swagger), and the exact response.

gerardsyd commented 9 months ago

Thanks - I'll look into 1. I tried actual:5006 (both http and https) but that did not work. I'll look into CORS for traefik. On 2, I don't necessarily want it to be publicly accesible but I'll try setting up a public endpoint for testing and see if that helps. I'll also switch of oauth on actual for testing and see if that solves things. Would you mind expanding on 3? what is the difference between actual api vs actual server? That bit confused me as not sure if you're referring to actual:5006 or actual.domainname or actualapi:5007 / localhost:5007

jhonderson commented 9 months ago

To your question, I am referring to the url of the actual http api container, in this case it would be actualapi:5007 if accessed within the docket network, or localhost:5007 if accessed outside the container network but in the machine where the container runs (likely this one). If you create a domain for actual api, it would be that domain.

gerardsyd commented 9 months ago

Thanks, really appreciate the help! I can get it to work by using actual:5006 as the ACTUAL_SERVER_URL and then running the curl from my server machine with: curl -X 'GET' \ 'http://localhost:5007/v1/budgets/{BUDGET-SYNC-ID}/accounts' \ -H 'accept: application/json' \ -H 'x-api-key: {API-KEY}'

Not sure why it still gives me the error message from the web GUI / swagger but it does what I need for now so I can the API through python. Appreciate all the assistance!