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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

Get Attachment API, return blank content

(1) ShareShare
ReportReport
Posted on by 5

Hi experts,

Could you help to see this issue, thanks for any advice!

when i use standard Get Attachment API:

api.businesscentral.dynamics.com/.../attachments eq 39aff85a-39c5-ec11-8e7e-00224858b413 and parentType eq 'Purchase Order'

response: there is no content in value, actually, we have attachment for the order

{
    "value": []
}
I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    This may help already:

    docs.microsoft.com/.../dynamics_attachment_get

    Thank you.

  • Anton Gerasimov Profile Picture
    20 on at

    I have the same question. The request status is OK, but nothing returned. It looks like GET attachment method in API v.2 is corrupted. v1.0. Neither does API v1. It attaches "?tenant=msft1...&aid=FIN'" in the end of GET request and returns "BadRequest_NotFound".

    I ask api.businesscentral.dynamics.com/.../attachments$filter=parentId eq 4d5ac3ef-15ab-ec11-bb8d-000d3a2b992c but it sends api.businesscentral.dynamics.com/.../{tenant id}/api/v1.0/companies({copmany id})/attachments$filter=parentId%20eq%204d5ac3ef-15ab-ec11-bb8d-000d3a2b992c?tenant=msft1a6720t40824025&aid=FIN'." instead

  • Suggested answer
    Bodhi Tectura Profile Picture
    5 on at
    In the Purchase Order API, return a base64 string of the attachment, it's ok now
    trigger OnAfterGetRecord()
        var
            PurchInvAggregator: Codeunit "Purch. Inv. Aggregator";

            TempBlob: Codeunit "Temp Blob";
            Base64Convert: Codeunit "Base64 Convert";
            DocumentAttachment: Record "Document Attachment";
            PurchaseHeader: Record "Purchase Header";
            Linstream: InStream;
            Loutstream: OutStream;
        begin
            attachmentText := '';
            DocumentAttachment.reset;
            DocumentAttachment.SetRange("Table ID", DATABASE::"Purchase Header");
            DocumentAttachment.SetRange("No.", Rec."No.");
            DocumentAttachment.SetRange("Document Type", DocumentAttachment."Document Type"::Order);
            if DocumentAttachment.FindLast() then begin
                TempBlob.CreateOutStream(Loutstream);
                DocumentAttachment."Document Reference ID".ExportStream(Loutstream);
                TempBlob.CreateInStream(Linstream);
                attachmentText := Base64Convert.ToBase64(Linstream);
                FileName := DocumentAttachment."File Name";
                FileExtension := DocumentAttachment."File Extension";
            end;
    end;
  • Anton Gerasimov Profile Picture
    20 on at

    Hi Bodhi Chen! Thank you for responding. But how to get the attachment via GET API? I have created the customer portal, and I have to download pdf attachments from business central via API. But I got an empty result the same as you.

  • Suggested answer
    Marco Mels Profile Picture
    Microsoft Employee on at

    Hello,

    If you do not get further traction from the community, feel free to raise it to Microsoft support via your partner or CSP.

    Thanks.

  • GFT Profile Picture
    5 on at

    Did anybody solve this issue? I have the same one...

  • Probes Profile Picture
    18 on at

    Hi Anton,

    We are having intermitted issues when using salesInvoiceLines API, getting the following error;

    Unable to create Sales Invoice/Line in Dynamics Business Central. Error from Dynamics Business Central: {

     "error": {

       "code": "BadRequest_NotFound",

       "message": "No HTTP resource was found that matches the request URI 'api.businesscentral.dynamics.com/.../{tenant id}/{environment name}/api/v1.0/companies({company id}/salesInvoices({id})/salesInvoiceLines?tenant=msweua9310t90710494&aid=FIN'."

    Did you manage to resolve your problem?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 653 Super User 2026 Season 1

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 414 Most Valuable Professional

#3
YUN ZHU Profile Picture

YUN ZHU 394 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans