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

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

  • 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
    95 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
    95 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
    95 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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans