POST /api/transactions/ - account_id object does not exist. #65

Closed
opened 2025-12-28 23:25:03 +01:00 by adam · 6 comments
Owner

Originally created by @RodrigoPrestes on GitHub (Oct 17, 2025).

Hello, I tried to create a new transaction using the API /api/transactions/ but it failed with HTTP error 400.

{\"account_id\":[\"Invalid pk \\\"4\\\" - object does not exist.\"]}

I had created the account through the GUI, when calling GET /api/accounts/ I receive this:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 4,
      "name": "Example account",
      "group": null,
      "currency": {
        "id": 2,
        "code": "USD",
        "name": "Dollar",
        "decimal_places": 2,
        "prefix": "$",
        "suffix": "",
        "is_archived": false,
        "exchange_currency": null
      },
      "exchange_currency": null,
      "is_asset": true
    }
  ]
}

So, it does return the account.
For reference here's the body I'm sending on the create transaction POST resquest:

{
  "category": "Games",
  "tags": [],
  "entities": ["1"],
  "account_id": 4,
  "reference_date": "2025-10-17",
  "type": "EX",
  "is_paid": true,
  "date": "2025-10-17",
  "mute": false,
  "amount": "100",
  "description": "Some text",
  "notes": "",
  "internal_note": "",
  "internal_id": null
}

I thought I might be missing something but the issue is very similar to https://github.com/eitchtee/WYGIWYH/issues/253.
One extra detail, I'm doing the POST request inside n8n, I created a second user for n8n and only gave the 'Can add Transaction' permission. I also tried adding the 'Can view Account' but I still get 400.

Originally created by @RodrigoPrestes on GitHub (Oct 17, 2025). Hello, I tried to create a new transaction using the API `/api/transactions/` but it failed with HTTP error 400. ``` {\"account_id\":[\"Invalid pk \\\"4\\\" - object does not exist.\"]} ``` I had created the account through the GUI, when calling GET `/api/accounts/` I receive this: ``` { "count": 1, "next": null, "previous": null, "results": [ { "id": 4, "name": "Example account", "group": null, "currency": { "id": 2, "code": "USD", "name": "Dollar", "decimal_places": 2, "prefix": "$", "suffix": "", "is_archived": false, "exchange_currency": null }, "exchange_currency": null, "is_asset": true } ] } ``` So, it does return the account. For reference here's the body I'm sending on the create transaction POST resquest: ``` { "category": "Games", "tags": [], "entities": ["1"], "account_id": 4, "reference_date": "2025-10-17", "type": "EX", "is_paid": true, "date": "2025-10-17", "mute": false, "amount": "100", "description": "Some text", "notes": "", "internal_note": "", "internal_id": null } ``` I thought I might be missing something but the issue is very similar to https://github.com/eitchtee/WYGIWYH/issues/253. One extra detail, I'm doing the POST request inside [n8n](https://github.com/n8n-io/n8n), I created a second user for n8n and only gave the 'Can add Transaction' permission. I also tried adding the 'Can view Account' but I still get 400.
adam closed this issue 2025-12-28 23:25:04 +01:00
Author
Owner

@eitchtee commented on GitHub (Oct 17, 2025):

Hey Rodrigo, hope you're enjoying WYGIWYH.

We currently don't support permission scoping, any permission added to the user via the Django Admin is ignored. The way it currently works is, basically, a user has full access to any account it creates, or is shared with it.

My suspicion is that your n8n user doesn't have access to the account you're trying to add a transaction to. You have two options:

  1. Share this account and any other you want to programatically access with the n8n user. To do this: Sidebar > Management > Accounts > Click the arrow button besides each account name and select your user on the Shared with field. Repeat this for any account you want.
  2. Or, use your own user to authenticate with the API.

Let me know if this fixes your issue.


P.S. Ideally, we should move to a Token based access on the API, with proper permissions, like you tried to do, but time has been really short lately to implement anything, hopefully someday.

@eitchtee commented on GitHub (Oct 17, 2025): Hey Rodrigo, hope you're enjoying WYGIWYH. We currently don't support permission scoping, any permission added to the user via the Django Admin is ignored. The way it currently works is, basically, a user has full access to any account it creates, or is shared with it. My suspicion is that your n8n user doesn't have access to the account you're trying to add a transaction to. You have two options: 1. Share this account and any other you want to programatically access with the n8n user. To do this: `Sidebar` > `Management` > `Accounts` >` Click the arrow button besides each account name and select your user on the Shared with field`. Repeat this for any account you want. 2. Or, use your own user to authenticate with the API. Let me know if this fixes your issue. --- P.S. Ideally, we should move to a Token based access on the API, with proper permissions, like you tried to do, but time has been really short lately to implement anything, hopefully someday.
Author
Owner

@RodrigoPrestes commented on GitHub (Oct 17, 2025):

That was it, I needed to share the account.
For my use case that's more than enough.
Thanks.

@RodrigoPrestes commented on GitHub (Oct 17, 2025): That was it, I needed to share the account. For my use case that's more than enough. Thanks.
Author
Owner

@avier99 commented on GitHub (Nov 27, 2025):

Hey @RodrigoPrestes possible you could share your n8n setup workflow?
i am having trouble connecting it with my wygiwyh!!

i am planning to link a sheet there to automatically import my transactions (temporarily)

@avier99 commented on GitHub (Nov 27, 2025): Hey @RodrigoPrestes possible you could share your n8n setup workflow? i am having trouble connecting it with my wygiwyh!! i am planning to link a sheet there to automatically import my transactions (temporarily)
Author
Owner

@RodrigoPrestes commented on GitHub (Nov 28, 2025):

Hi @avier99, here's how I've done it:


On the WYGIWYH side:

  • On the side menu I went Managment > Users > + Button
  • Created an user for n8n
  • Back on the side menu I went to Categories, clicked on the Share button (the ↱ arrow) of a category
  • On the Shared with users dropdown I selected the n8n user and then saved (This was the missing piece for me)

On the n8n side:

  • I created a Javascript node, named Create transaction, with this:
    (data is fictional, not hard coded on the real node)
const value = $('Other node').first().json.value;
const body = {
  "category": "Games",
  "tags": [],
  "entities": ["1"],
  "account_id": 4,
  "reference_date": "2025-10-17",
  "type": "EX",
  "is_paid": true,
  "date": "2025-10-17",
  "mute": false,
  "amount": value,
  "description": "Some text",
  "notes": "",
  "internal_note": "",
  "internal_id": null
};
return { body };
  • Then I created a HTTP Request node with these parameters set:
    Method = POST
    URL = http://wygiwyh.yourinstance.com:8000/api/transactions/, Replace the domain with your WYGIWYH URL
    Authentication = Generic Credential Type
    Generic Auth Type = Basic Auth
    Basic Auth = I had to create one, on the pencil icon on the right and then add the same credentials for the n8n user on WYGIWYH
    Send Query Parameters = off
    Send Headers = off
    Send Body = on
    Body Content Type = JSON
    Specify Body = Using JSON
    JSON = {{ $('Create transaction').first().json.body }}

Notes:

  • I do have other nodes extracting the data but in order to prepare and call WYGIWYH is just those two.
  • You can get IDs for your things (like accounts and categories) from https://wygiwyh.yourinstance.com/api/docs/.
  • If your're using Docker, make sure both containers are on the same network.

Been working flawlessly here.

@RodrigoPrestes commented on GitHub (Nov 28, 2025): Hi @avier99, here's how I've done it: --- On the WYGIWYH side: - On the side menu I went `Managment > Users > + Button` - Created an user for n8n - Back on the side menu I went to `Categories`, clicked on the Share button (the ↱ arrow) of a category - On the `Shared with users` dropdown I selected the n8n user and then saved (This was the missing piece for me) --- On the n8n side: - I created a Javascript node, named `Create transaction`, with this: (data is fictional, not hard coded on the real node) ```javascript const value = $('Other node').first().json.value; const body = { "category": "Games", "tags": [], "entities": ["1"], "account_id": 4, "reference_date": "2025-10-17", "type": "EX", "is_paid": true, "date": "2025-10-17", "mute": false, "amount": value, "description": "Some text", "notes": "", "internal_note": "", "internal_id": null }; return { body }; ``` - Then I created a HTTP Request node with these parameters set: Method = `POST` URL = `http://wygiwyh.yourinstance.com:8000/api/transactions/`, Replace the domain with your WYGIWYH URL Authentication = `Generic Credential Type` Generic Auth Type = `Basic Auth` Basic Auth = I had to create one, on the pencil icon on the right and then add the same credentials for the n8n user on WYGIWYH Send Query Parameters = `off` Send Headers = `off` Send Body = `on` Body Content Type = `JSON` Specify Body = `Using JSON` JSON = `{{ $('Create transaction').first().json.body }}` --- Notes: - I do have other nodes extracting the data but in order to prepare and call WYGIWYH is just those two. - You can get IDs for your things (like accounts and categories) from https://wygiwyh.yourinstance.com/api/docs/. - If your're using Docker, make sure both containers are on the same network. --- Been working flawlessly here.
Author
Owner

@eitchtee commented on GitHub (Nov 28, 2025):

Going by memory here, but I'm pretty sure you don't even need ids for most things, passing a string should work. e.g.:
account: "My Account",
category: "My category",
tags: ["My tags"],
entities: ["my entity"]

And for category and tags, they should get created automatically if they don't exist when doing this.

@eitchtee commented on GitHub (Nov 28, 2025): Going by memory here, but I'm pretty sure you don't even need ids for most things, passing a string should work. e.g.: account: "My Account", category: "My category", tags: ["My tags"], entities: ["my entity"] And for category and tags, they should get created automatically if they don't exist when doing this.
Author
Owner

@avier99 commented on GitHub (Nov 28, 2025):

thanks @RodrigoPrestes ; will try it out soon

@avier99 commented on GitHub (Nov 28, 2025): thanks @RodrigoPrestes ; will try it out soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#65