Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Get attachment from a Sales Order in Business Central using HTTP Request

Posted on by 5

Hi, I am trying to create a flow to get an attachment from  a Sales Order record in Business Central using the HTTP premium connector following this doc:

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_get

I tried using this URI

https://api.businesscentral.dynamics.com/v2.0/"Tenant GUID"/"Environment Name"/api/v2.0/companies("Company GUID")/attachments

Results:

You must specify a parentId in the request body.  CorrelationId:  1f77a56c-ca65-4708-9596-88f42eece818.

Then, I tried adding a parentId:

api.businesscentral.dynamics.com/.../"Environment Name"/api/v2.0/companies("Company GUID")/attachments?$filter=parentId eq "Sales Order GUID"

Results:

You must specify a document id and a document type to get the attachments.  CorrelationId:  53c5101e-c8e4-402b-a084-f143326a843c.

I added the document type:

api.businesscentral.dynamics.com/.../"Environment Name"/api/v2.0/companies("Company GUID")/attachments?$filter=parentId eq "Sales Order GUID" and parentType eq salesOrder

Results:

A binary operator with incompatible types was detected. Found operand types 'Microsoft.NAV.attachmentEntityBufferDocumentType' and 'Microsoft.NAV.salesOrder' for operator kind 'Equal'.  CorrelationId:  e9233a17-266e-4816-bd41-3a4d437c7a14.

This is the only one that does get a "200 Status code" but the results are blank:

api.businesscentral.dynamics.com/.../"Environment Name"/api/v2.0/companies("Company GUID")/salesOrders("Sales Order GUID")/attachments

I have double-checked and the sales order record does have an attachment (PDF) linked.

I have also tried using the "Get File, Image, Document V3" connector for Business Central but I am not able to retrieve it from Sales Order, it does work for "Posted Sales Invoices"

So the question is, is it possible? and if so, what should the URI look like?

Thanks in advance for any suggestions.

Categories:
  • RE: Get attachment from a Sales Order in Business Central using HTTP Request

    What I mean is that, the way to make this API work is to attach the file using this path:

    In your Sales Order record, go to Prepare > Incoming Document > Create Incoming Document from File.

    This will not work:

    {

    What I mean by "regular" is attaching the file by clicking on Attachments inside the FactBox pane on the right-side of your screen.

    Or by going to Related > Order > Attachments.

    }

    If you need to attach multiple files, go to Prepare > Incoming Document > View Incoming Document, then again to Prepare > Attach File.

    There you can attach multiple files in your Incoming Document.

    If you still not getting the JSON from BC, then you should check your authentication.

  • Wiadvance Profile Picture
    Wiadvance 5 on at
    RE: Get attachment from a Sales Order in Business Central using HTTP Request

    what do you mean about " incoming document" and "regular" ?

    I have two attachments with links on BC web page, but this API retrieve nothing.

    api.businesscentral.dynamics.com/.../"ENV NAME"/api/v2.0/companies("COMPANY GUID")/salesOrders("SALES ORDER GUID")/attachments

  • Suggested answer
    VicenteGuti Profile Picture
    VicenteGuti 5 on at
    RE: Get attachment from a Sales Order in Business Central using HTTP Request

    Hey guys,

    Thanks for the help! I was able to solve it using this URI:

    api.businesscentral.dynamics.com/.../"ENV NAME"/api/v2.0/companies("COMPANY GUID")/salesOrders("SALES ORDER GUID")/attachments

    The issue was that the attachment needs to be an incoming document, not as a "regular" attachment in BC.

  • Verified answer
    Kerry Evans Profile Picture
    Kerry Evans 165 on at
    RE: Get attachment from a Sales Order in Business Central using HTTP Request

    Based on the error messages that you have received, it seems that you are not providing the correct parameters required to retrieve the attachment from the Sales Order record. Here is an example URI that you can try using to retrieve the attachment from the Sales Order record in Business Central:

    api.businesscentral.dynamics.com/.../<Tenant ID>/<Environment ID>/api/v2.0/companies('<Company ID>')/salesOrders('<Sales Order ID>')/attachments('<Attachment ID>')/Microsoft.NAV.getFile

    Replace <Tenant ID>, <Environment ID>, <Company ID>, <Sales Order ID>, and <Attachment ID> with the appropriate values.

    In addition, make sure that you are using the correct parentType parameter value in your filter. According to the Microsoft documentation, the correct value for parentType for Sales Order records is "SalesOrderHeader".

    Hope this helps!

  • YUN ZHU Profile Picture
    YUN ZHU 73,696 Super User 2024 Season 2 on at
    RE: Get attachment from a Sales Order in Business Central using HTTP Request

    Hi, Josh has a great post about this that hopefully gives you some hints.

    https://joshanglesea.wordpress.com/2021/01/25/business-central-attachmentsapi/

    Thanks.

    ZHU

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans