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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Unable to Post Media Data to Custom API in Business Central

(4) ShareShare
ReportReport
Posted on by 10
I have created a custom field with the Media data type in the Customer table using a table extension

Table Extension

tableextension 50100 "Customer Extension" extends Customer
{
    fields
    {
        field(50101; "Customer Image"; Media)
        {
            Caption = 'Customer Image';
            DataClassification = ToBeClassified;
        }
        field(50102; "MediaSet"; MediaSet)
        {
            Caption = 'MediaSet';
            DataClassification = ToBeClassified;
        }
    }
}

Then, I created a custom API page to expose this field:

Customer API Page
 
page 50100 CustomerCustomApi
{
    APIGroup = 'CJG';
    APIPublisher = 'CJAPI';
    APIVersion = 'v1.0';
    ApplicationArea = All;
    Caption = 'customerCustomApi';
    DelayedInsert = true;
    EntityName = 'CustomerCustom';
    EntitySetName = 'CustomerCustom';
    PageType = API;
    SourceTable = Customer;
    ODataKeyFields = SystemId;
    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(customerImage; Rec."Customer Image")
                {
                    Caption = 'Customer Image';
                }
            }
        }
    }
}

API Endpoint for Customer API

https://api.businesscentral.dynamics.com/v2.0/{Sandbox}/api/{APIPublisher}/{APIGroup}/v1.0/companies({CompanyId})/CustomerCustom

 

Problem Statement:

To post data in the Media field (Customer Image), I created another custom API page for Tenant Media to upload media and get the ID, which I can then use to update the Customer Image field.

However, I am unable to post data to Tenant Media API. Below is my API page:

Tenant Media API Page

page 80193 Media
{
    APIGroup = 'CJG';
    APIPublisher = 'CJAPI';
    APIVersion = 'v1.0';
    ApplicationArea = All;
    Caption = 'media';
    DelayedInsert = true;
    EntityName = 'TenantMedia';
    EntitySetName = 'TenantMedia';
    PageType = API;
    SourceTable = "Tenant Media";

    layout
    {
        area(Content)
        {
            repeater(General)
            {
                field(companyName; Rec."Company Name")
                {
                    Caption = 'Company Name';
                }
                field(content; Rec.Content)
                {
                    Caption = 'Content';
                }
                field(creatingUser; Rec."Creating User")
                {
                    Caption = 'Creating User';
                }
                field(description; Rec.Description)
                {
                    Caption = 'Description';
                }
                field(expirationDate; Rec."Expiration Date")
                {
                    Caption = 'Expiration Date';
                }
                field(fileName; Rec."File Name")
                {
                    Caption = 'File Name';
                }
                field(height; Rec.Height)
                {
                    Caption = 'Height';
                }
                field(id; Rec.ID)
                {
                    Caption = 'ID';
                }
                field(mimeType; Rec."Mime Type")
                {
                    Caption = 'Mime Type';
                }
                field(prohibitCache; Rec."Prohibit Cache")
                {
                    Caption = 'Prohibit Cache';
                }
                field(width; Rec.Width)
                {
                    Caption = 'Width';
                }
            }
        }
    }
}

API Endpoint for Tenant Media API

https://api.businesscentral.dynamics.com/v2.0/{Sandbox}/api/{APIPublisher}/{APIGroup}/v1.0/companies({CompanyID})/TenantMedia

 

Try 1)Request Body (POST to Tenant Media API)

{
    "fileName": "customerImage.png",
    "mimeType": "image/png",
    "description": "Customer Profile Image",
    "Height": 5,
    "Width": 10
}

Errors Encountered:

{
    "error": {
        "code": "Application_FieldValidationException",
        "message": "ID must have a value in Tenant Media: ID={00000000-0000-0000-0000-000000000000}. It cannot be zero or empty.  CorrelationId: a43d42bf-f9bf-4587-b231-8191a6611e9e."
    }
}

Try 2) : When posting with a manually generated ID

{
    "error": {
        "code": "Internal_ServerError",
        "message": "Sorry, the current permissions prevented the action. (TableData 2000000184 Tenant Media Insert: CJPortalAL)  CorrelationId: fb15774d-520d-4135-991f-f7dc4f1e6f1f."
    }
}

Steps Already Taken:

  • Added Tenant Media RMID permissions to the user and Microsoft Entra Application.
  • Tried both with and without manually providing the ID.
  • Ensured API permissions are correctly configured.

Questions:

1️⃣ How can I correctly post media data to the Tenant Media table using my API?
2️⃣ Once uploaded, how can I use the returned ID to update the Customer Image (Media field) in my CustomerCustomApi?
3️⃣ What is the correct way to handle MediaSet fields via API?

Any guidance or working examples would be greatly appreciated!

 
I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    25,236 Most Valuable Professional on at
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,603 Super User 2025 Season 2 on at

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

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 2,238

#2
YUN ZHU Profile Picture

YUN ZHU 773 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 630

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans