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

Announcements

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)
  • Suggested answer
    raelhefn Profile Picture
    Microsoft Employee on at

    Hi Ankit,

    could you please try to use postman and simply perform the following:

    1. Open postman type post query :

    POST: localhost:6048/.../attachments

    And in Body

    {

       "parentId" : "3af6e05a-075c-eb11-89f9-000d3a2dc4a1", //sales invoice id

       "fileName": "myPDF.pdf"

    }

    make sure requested service is deployed into your environment and it is accessible. 

    community.dynamics.com/.../how-to-test-api-s-in-d365-business-central

  • Ankit Surana Profile Picture
    35 on at

    Hi Raelhefn,

    Appreciate your response.

    I Have tried this. it works but how to add attachment content in the request? That my main question?

    Can you please also guide me on how to achieve this?

    Looking forward to your response.

    With Kind Regards,

    Ankit

  • raelhefn Profile Picture
    Microsoft Employee on at

    It appears that the File Content is a stream that is open during your call. Create Record most likely is complaining about it. Although I am not sure it will work, try saving the File Content to a variable and save the variable to Business Central.

    learning.postman.com/.../

  • Ankit Surana Profile Picture
    35 on at

    Hi Raelhefn,

    I tried and it still didn't work. This also resulted in the same error response. Can you please help ?

    Request:

    {

     "parentId": "3af6e05a-075c-eb11-89f9-000d3a2dc4a1",

     "fileName": "Work_Order-00005-20210121174035.pdf",

     "byteSize": "44033",

     "attachmentContent": "{{Attachment}}"

    }

    Looking forward to your response.

    With Kind Regards,

    Ankit

  • Verified answer
    alex_li Profile Picture
    60 on at

    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

  • Suggested answer
    JAngle Profile Picture
    150 on at

    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.

  • Ankit Surana Profile Picture
    35 on at

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

    Please see the attachment for Reference

    pastedimage1611930087460v1.png

  • Ankit Surana Profile Picture
    35 on at

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

    Please see the attachment for Reference

    pastedimage1611930681852v1.png

  • Suggested answer
    JAngle Profile Picture
    150 on at

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

  • alex_li Profile Picture
    60 on at

    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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,282 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,212 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,123 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans