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

Notifications

Announcements

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)
  • 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();

                   }

  • Suggested answer
    JAngle Profile Picture
    137 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

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

News and Announcements

Season of Giving Solutions is Here!

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 1,457

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 742 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 669 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans