Summary
I’m trying to build a custom PDF viewer widget that displays PDF content from an Ontology object’s media reference property, but I’m unable to fetch the actual media content despite trying multiple approaches.
Environment
-
Widget Type: Custom React Widget with OSDK
-
OSDK Version: 2.4.0
-
@osdk/client Version: 2.6.1
-
Object Type:
HmMtcHeatNumber -
Media Property:
mergedPdfMediaReference(type:mediaReference)
Goal
Fetch and display PDF content from an object’s mediaReference property using the object’s primary key in a Custom Workshop Widget.
Attempts Made
Attempt 1: Using OSDK fetchContents() Method
import { client } from "./client";
import { HmMtcHeatNumber } from "@custom-widget/sdk";
const result = await client(HmMtcHeatNumber).fetchOne(objectPrimaryKey);
const response = await result.mergedPdfMediaReference?.fetchContents();
const blob = await response.blob();
Error:
{
"errorCode": "INVALID_ARGUMENT",
"errorName": "Api:UnknownField",
"errorInstanceId": "9cdf1ccb-d3cf-4847-9ece-01294cd97c12",
"parameters": {
"unknownField": "selectV2"
}
}
Attempt 2: Direct Ontology Media API Call
const mediaResponse = await fetch(
`${window.location.origin}/api/v2/ontologies/${ontologyRid}/objects/HmMtcHeatNumber/${encodeURIComponent(objectPrimaryKey)}/media/mergedPdfMediaReference/content`,
{
credentials: "include",
headers: {
"Accept": "application/pdf",
},
}
);
Error:
{
"errorCode": "INVALID_ARGUMENT",
"errorName": "Widgets:ApiFeaturePreviewUsageOnly",
"errorInstanceId": "9b390007-f930-4d67-8065-dd9d16a469d7",
"parameters": {}
}
Attempt 3: Parsing Media Reference JSON and Using MIO API
Media Reference JSON received:
{
"mimeType": "application/pdf",
"reference": {
"mediaSetViewItem": {
"mediaSetRid": "ri.mio.main.media-set.xxx",
"mediaSetViewRid": "ri.mio.main.view.xxx",
"mediaItemRid": "ri.mio.main.media-item.xxx",
"token": null
},
"type": "mediaSetViewItem"
}
}
API Call:
const apiUrl = `${window.location.origin}/mio/api/mediaItems/${mediaItemRid}/content?mediaSetRid=${encodeURIComponent(mediaSetRid)}`;
Error:
Failed to load PDF: Not Found
Questions
-
Is it possible to access media reference content from within a Custom Workshop Widget?
-
If yes, what is the correct API endpoint or OSDK method to use?
-
Does the
Widgets:ApiFeaturePreviewUsageOnlyerror indicate a feature flag or permission that needs to be enabled? -
What is the recommended approach for displaying PDF content from an object’s media reference property in a Custom Widget?
Additional Context
-
The widget builds and deploys successfully (CI checks pass)
-
The issue occurs at runtime when trying to fetch the actual media content
-
Workshop’s built-in widgets can display media content from the same property without issues
-
The media reference property is properly configured and contains valid data
Any guidance would be greatly appreciated!