Skip to main content
Community site session details

Community site session details

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

API Attachments on Journal Gen Line

(1) ShareShare
ReportReport
Posted on by 420
Hi 
On BC SAAS latest release i want to use API to attach a incoming document on a Gen, Jnl Line (This is also created by API),

I don't know which page or code unit to add in web services , or is there any standard endpoint available for same,

please help. do i need to expose any object to OData web services or not.
  • Suggested answer
    Sohail Ahmed Profile Picture
    8,100 Super User 2025 Season 2 on at
    API Attachments on Journal Gen Line
    There’s no standard API to attach documents directly to General Journal Lines. You’ll need to create a custom API page that handles file upload (using a Media or BLOB field), store it as an Incoming Document, then link it to the journal line using the Incoming Document Entry No. field.
     
    ✅ Mark this as the verified answer if helpful.
     
     
  • Suggested answer
    DAnny3211 Profile Picture
    9,724 Moderator on at
    API Attachments on Journal Gen Line

    Hello,

    Thank you for your question.

    In the latest release of Business Central SaaS, attaching an incoming document to a General Journal Line via API is not supported through a standard endpoint out of the box. However, there are a few approaches you can consider:

    Recommended Approach:

    1. Expose the Relevant Page via OData
      To enable attachment functionality via API, you will likely need to expose a custom page or codeunit through OData web services. The standard General Journal Line page does not include attachment capabilities by default.

    2. Use the Incoming Document Attachments Table
      You can interact with the Incoming Document Attachments table (Table 133) and link it to the journal line using the appropriate keys. This may require a custom API page or codeunit to handle the logic.

    3. Create a Custom API Page
      If your scenario involves creating both the journal line and the attachment via API, consider building a custom API page that:

      • Accepts the journal line data.
      • Accepts the document (e.g., as a media field or blob).
      • Links the document to the journal line using internal references.
    4. Use the Media or MediaSet Data Types
      For file uploads, use Media or MediaSet fields in your custom API page to handle incoming documents. Ensure the page is properly exposed and published in the Web Services page.

    5. Security and Permissions
      Ensure that the Entra Application or user making the API call has the necessary permissions to access and modify both the journal lines and the attachment records.

    If this response helps resolve your issue, please consider marking it as accepted so it may assist others with similar requirements.

    Best regards.

  • Suggested answer
    Sumit Singh Profile Picture
    502 on at
    API Attachments on Journal Gen Line
    BC provides a standard API for managing attachments, which are internally represented as Incoming Documents (Table 130).
    Create Attachment Endpoint
    You can use the following endpoint to attach a document:
    POST /businesscentralPrefix/companies({companyId})/attachments
    Request Body Example:
    {
      "parentId": "GUID of the Gen. Journal Line",
      "parentType": "Journal",
      "fileName": "invoice.pdf",
      "attachmentContent": "base64-encoded-file-content"
    }
    • parentId: The system ID of the General Journal Line.
    • parentType: Use "Journal" for General Journal Lines.
    • attachmentContent: The file content encoded in Base64 [1] [2].
    Note: The file must be uploaded as a Base64 string. No need to expose custom objects unless you need more control or metadata.
    How to Get the Journal Line ID
    If you're creating the General Journal Line via API, the response will include the id (GUID) of the line. Use this as the parentId in the attachment API.
    Do You Need to Expose Any Page or Codeunit?
    No, if you're using the standard API. The attachments endpoint is already available in the v2.0 API and supports GET, POST, PATCH, and DELETE operations for attachments[1].
    However, if you want to:
    • Attach documents to custom entities
    • Add additional metadata
    • Trigger business logic (e.g., validations or workflows)
    Then you must expose a custom codeunit or page via OData or create a custom API page.

    Alternative: OData V4 Unbound Actions
    If you prefer OData or need to perform complex logic (e.g., linking to posted entries), you can:
    • Create a Codeunit with procedures
    • Expose it as an OData V4 unbound action
    • Call it from external systems
    References
    [1] GET attachments - Business Central | Microsoft Learn
    [2] Business Central API v2.0 Create Attachment request JSON
    [3] Work with incoming documents - Business Central | Microsoft Learn

    Note: This response was created in collaboration with Microsoft Copilot to ensure clarity and completeness. I hope it helps to some extent.
    Mark the Answer as Verified if this is Helpful.
     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

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

#1
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 3,878

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 3,583 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 3,175 Super User 2025 Season 2

Featured topics

Product updates

Dynamics 365 release plans