How to upload attachments for explanations?

Hi all, I need help! The API documentation shows clear examples of how to download attachments via the api (associated with bank explanations) but does not show how to upload them. The field concerned is given in the download example as a url which makes no sense for an upload since it is set by Freeagent to the location on Amazon S3 where Freeagent decides to store the attachment. Can anybody give me any pointers/code snippet? Thanks in advance.

Hi @Cberridge,

Thanks for your question! If I understand you correctly, you’re asking for how you can upload attachments associated with bank explanations through the API. You note that our documentation on this only provides examples about how to do this using attachments that already exist in FreeAgent.

I think there is another option which will help you. The bank transaction explanations attributes shows that an attachment can have a data component, which is a base64 encoded representation of the attribute. As indicated there, this can be up to 5MB in size. So using this you should be able to upload an attachment at the same time as the explanation.

A common gotcha working with base64 encoders like this is that the data field must only contain the raw base64 encoded data, not any preamble that may come back from encoders (such as JavaScript’s FileReader)

Interestingly, I note we don’t show the url version of the attachment attribute here in the docs. We’ll need to fix that at some point.

I hope that helps! If I’ve misunderstood your question, or you want some clarification, do let us know.

Best regards,

Hi James,

Thanks for the reply. So I am trying something like this in a post to /bank_transaction_explanations and I get 500 Internal Server error as a response - kinda hard to debug. Am I missing some fields? Many thanks in advance.

{“bank_transaction_explanation”: {
“category”: “”,
“dated_on”: “2017-06-08”,
“description”: “M&S SIMPLY FOOD - ON 08 JUN///”,
“gross_value”: “-7.5”,
“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”
“bank_transaction”: “

FYI, Managed to sort this… problem was poorly formatted data. This approach does work!

1 Like

Hi @Cberridge,

Sorry to not have gotten back to you earlier. I’m glad to hear that you’ve gotten this working, and that it lets you achieve your goal. When you say the problem you had was poorly formatted data, do you mean the base64 encoded data you sent to the API?

I’m curious to understand if there’s anything we can do to improve our error messages here.

Thanks again for the question - I’m sure it’ll help others

No… it was purely my mistake!