I would like to “Update” existing Bank Transaction Explanations via the API and add attachments to them.
Unfortunately, although I can work out what the attachment data needs to look like, ie:
“attachment”:
{
“file_name”: “2017-06-08 7.50.pdf”,
“data”: “JVBERi0xLjMKJcT —— (lots and lots more in here) —— IF0gPj4Kc3RhcnR4cmVmCjQwMjE2MwolJUVPRgo=”,
“description”: “(auto upload)”,
“content_type”: “application/x-pdf”
}
If I try and run an update on the bank_transaction_explanation object i get a 400 bad request response.
My current thinking is to take the JSON from the existing “bank_transaction_explanation” object and PUT the whole thing back to the API with the attachment object now in it. That didn’t work. So I then tried just doing a PUT with the transaction ID and the attachment object only (assuming it only wanted the fields that I wanted to update), but that didn’t work either (same response 400 error).
I stumbled across this topic - How to upload attachments for explanations? - #3 by Cberridge - but it’s akin to an old xKCD cartoon - “What did you see Cberridge?!?! What did you see?!”. He seems like he was trying to do the same thing as me, then somehow worked it out but didn’t explain how, what, why.
If someone could give me an example PUT request to update a bank_transaction_explanation which adds an attachment, that would be great - preferably with dummy data. Would be great if the documentation was then also updated with this info for anyone in the future.
Does your data contain any line feeds? I seem to recall when I was writing code to do this I had to use Ruby’s strict_encode64, not encode64 (which adds line feeds every 60 encoded characters).
I can’t see anything wrong with your JSON snippet. What does your whole JSON payload look like?
Ewa here from the Engineering Team at FreeAgent — thanks for your message on our forum and I’ll do my best to help out.
I believe I managed to isolate your API requests in our application logs – the main thing that strikes me is that I don’t see the parsed details of your request body at all, which may mean that the body is not getting properly included. I can see that the status of the responses you’re getting is 400, what error message is it accompanied by?
I’ve just worked it out. I wasn’t sending a “Content-Type” header, which needed to be “application/json” as soon as I did that, it all sprung into life.
I assume that your API is actually throwing my body data away as it doesn’t see a content-type header which is why you’re seeing nothing at your end.
Thanks Peter for leaving this here for others to use. I too want to upload a pdf to a bank transaction explanation. I’m a api newbie, using n8n to access the api and can’t get this to work for me.
App name: My FA app
Timestamp: 05/02/2025, 07:57:10