Notifications
Announcements
No record found.
Hi Business Central Community,I am trying to create an attachment for a Purchase Invoice. As I understand from the documentation (https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_create). My JSON should look like:{ "parentId": <the ID from the Purchase Invoice>, "parentType: "Purchase Invoice", "fileName": <for example 'document.pdf'>, "attachmentContent": <'stream'???>}What is supposed to be "stream", which they referred to in the documentation? I tried to encode in Base64 string but that doesn't work.
Hi, hope the following helps.
https://joshanglesea.wordpress.com/2021/01/25/business-central-attachmentsapi/
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_create
Thanks.
ZHU
Hi Yun, thanks for linking the documentation! I got it to upload the file.
One question remains though. I see that the attachment is in Incoming Document Files. How do I make it go to Attachments section?
Hi, An attachment in the Business Central standard API is defined as an Incoming Document (table 130)
So if you need Attachments section, you need to customize your own API.
More details: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-custom-api
Hope this helps.
Thanks Yun, I will take a look at custom API. Similarly, if I want to post Purchase Invoice to Posted Purchase Invoice, do I also need custom API?
Hi, yes.
Hope the following helps.
Or, you can use OData V4 Bound Action.
More details: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-creating-and-interacting-with-odatav4-bound-action
Hi ZHU,
Tried to follow all the steps in the first and second links mentioned by you. I am able to create and patch the file. Just wanted to know whether I convert the file to Base 64 encoding for sending when using C#?
HI, Sorry I haven't tried it, but it looks like it might work.
https://stackoverflow.com/questions/25919387/converting-file-into-base64string-and-back-again
Thanks.ZHU
Hi Syed, I'm using Java, but I didn't need to do the base64 encoding. Here is what I do in Postman and what it translates to in C# RestSharp:
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
OussamaSabbouh 3,143
Jainam M. Kothari 1,694 Super User 2025 Season 2
YUN ZHU 1,067 Super User 2025 Season 2