web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Business Central API v2.0 Create Attachment request JSON

(0) ShareShare
ReportReport
Posted on by 103

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.

I have the same question (0)
  • Verified answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at
  • tl2022 Profile Picture
    103 on at

    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?

    Screenshot_5F00_20221130_5F00_143033.png

  • Verified answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    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.

    pastedimage1669849909093v1.png

    More details: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-custom-api

    Hope this helps.

    Thanks.

    ZHU

  • tl2022 Profile Picture
    103 on at

    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?  

  • Verified answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    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

    Hope this helps.

    Thanks.

    ZHU

  • Syed Sajjad Hasan Profile Picture
    10 on at

    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#?

  • Suggested answer
    YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    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

    pastedimage1670544594867v1.png

    Hope this helps.

    Thanks.
    ZHU

  • tl2022 Profile Picture
    103 on at

    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:

    pastedimage1670545135716v2.png

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,143

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,694 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,067 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans