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

Community site session details

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

Api attachments

(0) ShareShare
ReportReport
Posted on by 35

Hi Team,

Can you please guide me on how to work with the API of "attachment" to attach the document to "Sales Order" or "Sales Invoice"?

I have tried sending the attached request as per documentation, but it fails with the below response:

Request:

AttachmentRequest.txt

Response:

{"error":{"code":"BadRequest","message":"Read called with an open stream or textreader. Please close any open streams or text readers before calling Read.  CorrelationId:  910e6436-db62-48c5-a739-0e87dcdba8be."}} 

Can you please help us in this scenario.

Looking forward to your responses.

Thanks & Regards,

Ankit

I have the same question (0)
  • dynamicsdevman Profile Picture
    30 on at
    RE: Api attachments

    I got this working by setting "If-Match" header value as "*" instead of the "W\" value of odata.etag response in POST API call. Thanks much.

  • dynamicsdevman Profile Picture
    30 on at
    RE: Api attachments

    After changing the version to v1.0, getting the error response message as below,

    pastedimage1649079911261v1.png

    Am i missing anything here?

  • dynamicsdevman Profile Picture
    30 on at
    RE: Api attachments

    When replacing the api version to v1.0, getting a response error message as below,

    pastedimage1649079739923v1.png

    I know this thread is a year old. But is there any resolution for uploading the attachment content? Much appreciate your help.

  • Suggested answer
    JAngle Profile Picture
    113 on at
    RE: Api attachments

    Directly no. Pattern I’ve tried is having a stand alone table/page. Once a record is added then passing it to the real attachments location. There is a series of blogs like this one that explain it to a point: www.sauravdhyani.com/.../msdyn365bc-test-base64-conversion-via_14.html

  • alex_li Profile Picture
    60 on at
    RE: Api attachments

    Hi Josh, is it possible to attach a file to Sales entities through BC api?

    The method we described earlier works perfect for those entities that have Incoming Document tab.

    But for  Sales Order and Sales Invoice  this tab is absent. There is only the "Attachments" one.

    pastedimage1612170950144v1.png

  • Suggested answer
    JAngle Profile Picture
    113 on at
    RE: Api attachments

    Change the second v2.0 to v1.0. I got the same error as you until I flipped to that

  • Ankit Surana Profile Picture
    35 on at
    RE: Api attachments

    i tried as per your suggestion , but it still doesnt work.

    Please see the attachment for Reference

    pastedimage1611930681852v1.png

  • Ankit Surana Profile Picture
    35 on at
    RE: Api attachments

    i tried as per your suggestion , but it still doesnt work.

    Please see the attachment for Reference

    pastedimage1611930087460v1.png

  • Suggested answer
    JAngle Profile Picture
    113 on at
    RE: Api attachments

    Late to the party but I had to explain this to a customer a few days back so did this post: joshanglesea.wordpress.com/.../

    Since had it working in Power Automate as well.

  • Verified answer
    alex_li Profile Picture
    60 on at
    RE: Api attachments

    You need first to create an attachment in your BusinessCentral record by sending the POST request as it was described earlier. As a result you receive an attachment id that can be used as follows:

    pastedimage1611846401182v1.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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sumit Singh Profile Picture

Sumit Singh 2,727

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 2,681 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 2,288 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans