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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

How to attach file to purchase invoice In Attachment Tab In dynamic 365 business central

(0) ShareShare
ReportReport
Posted on by

I am trying to attach a file to the Purchase Invoice in the Attachment Tab by using the Odata service of Page  20039  in dynamic 365 BC.

but I am not able to send the content of the file using this service. please guide me on how to attach the content of the file using Odata service of Page  20039.

Thanks in advance.

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    150 on at

    page 20039 is the api page. The method is like this:

    endpoint is like this with a POST command:

    https://api.businesscentral.dynamics.com/v2.0/<tenantID>/production/api/v1.0/companies(<companyID>)/attachments

    Use a body value like this 

    {
        "parentId" : "09dffb1f-7561-4622-a880-061bc42dc9a6",
        "fileName": "JA.pdf"
    }
    The parentId is the purchase invoice ID (guid), filename is whatever you want, within context of the attachment.
    The response of this will include an ID value. You need this ID value as it represents the data added to the incoming documents table.
    After that a PATCH command is needed

    ParentID is the document ID from BC and the ID for the attachment - provided in the response to the POST command

    https://api.businesscentral.dynamics.com/v2.0/<tenantID>/production/api/v1.0/companies(<companyID>)/attachments(parentId=<PurchaseInvoiceID>,id=<IDfromPOSTresponse>)/content

    in the body place the attachment file itself

  • Community Member Profile Picture
    on at

    @Josh Anglesea

    Thanks for your Reply,

    Can you please also guide me on how to send the attachment file in body, I mean What should be the Content-type of PATCH command is it JSON or anything else? and which format should I send the attachment file In a stream? I am trying to send an attachment file like below

     byte[] fileByte = DownloadAttachment(Attachmenturl);

                   Stream Stream = new MemoryStream(fileBye);

                   Dynamic365BCAttachmentContent Dynamic365BCAttachmentContent = new Dynamic365BCAttachmentContent();

                   Dynamic365BCAttachmentContent.attachmentContent = Stream;

                   string jsonContent = JsonConvert.SerializeObject(Dynamic365BCAttachmentContent);

                   string ResposeJson1 = "";

                   using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))

                   {

                       streamWriter.Write(jsonContent);

                       streamWriter.Close();

                   }

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 1,986 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,071 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 975 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans