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