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

Community site session details

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

Custom API for Item details with Pictures

(1) ShareShare
ReportReport
Posted on by 163
Hi All,

We are using On-Prem Business central,

i want to create a custom API which will send item detail , sales price detail and item picture with picture URL or binary string. i tried but in the picture content we are receiving only the media link URL and i don't know i to use this media link to show data in my web page, actually another application consuming this api.

below is my code.
 
query 50112 GetCustomerWithOrder
{
    QueryType = API;
    APIPublisher = 'QueryV1';
    APIGroup = 'QueryGroup';
    EntityName = 'Item';
    EntitySetName = 'Items';
 
    elements
    {
        dataitem(ItemDetails; Item)
        {
            column(ItemNo; "No.")
            {
 
            }
            column(Name; Description)
            {
 
            }
            column(Inventory; Inventory)
            {
 
            }
            column(Picture; Picture)
            {
 
            }
            column(Base_Unit_Price; "Unit Price")
            {
 
            }
            dataitem(Pricelist; "Sales Price")
            {
                DataItemLink = "Item No." = ItemDetails."No.";
                SqlJoinType = LeftOuterJoin;
                column(Unit_Price; "Unit Price")
                {
 
                }
                dataitem(pictures; "Picture Entity")
                {
                    DataItemLink = Id = ItemDetails.Picture;
                    SqlJoinType = LeftOuterJoin;
                    column(PictureContent; Content)
                    {
 
                    }
                }
            }
 
        }
    }
 
    var
        myInt: Integer;
 
    trigger OnBeforeOpen()
    begin
 
    end;
}
 
if anyone have any idea please let me know or you have any code snip you can share with me.

Thanks for your help.
 
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,307 Super User 2025 Season 2 on at
    Custom API for Item details with Pictures
    Hi, When you open this table directly, is there any data?
    The normal practice is Picture (Item table) ->  Content (table 2000000184 "Tenant Media")
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Umut Dogan Koc Profile Picture
    87 on at
    Custom API for Item details with Pictures
    Hello,
     
    You need to convert pictures into base64 format in API and consuming application should convert it back from base64 to picture.
    I would suggest you to use page API instead of query API. 
    Pictures are stored in Tenant Media record, so you need to get Tenant Media record for the picture. And content should be converted to Base64.
     local procedure SetValuesFromMediaID(MediaID: Guid)
        var
            TenantMedia: Record "Tenant Media";
        begin
            // TODO: This code should be replaced once we get a proper platform support
            // We should not build dependencies to TenantMedia table
            if IsNullGuid(MediaID) then
                exit;
     
            TenantMedia.SetAutoCalcFields(Content);
            if not TenantMedia.Get(MediaID) then
                exit;
     
            "Mime Type" := TenantMedia."Mime Type";
            Width := TenantMedia.Width;
            Height := TenantMedia.Height;
     
            Content := TenantMedia.Content;
        end;
     
    I'm putting a sample code works for company information picture, you need to fit this to tenant media:
     procedure GetCompanyLogoBase64(): Text
        var
            Base64: Codeunit "Base64 Convert";
            Tempblob: Codeunit "Temp Blob";
            OutS: OutStream;
            InS: InStream;
            Base64Txt: Text;
        begin
            rec.CalcFields(Picture);
            if Picture.HasValue then begin
                Tempblob.FromRecord(Rec, Rec.FieldNo(Picture));
                Tempblob.CreateInStream(InS);
                Base64Txt := Base64.ToBase64(InS);
                exit(Base64Txt);
            end;
        end;

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 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans