dmAPI.dynamicPageApi().isDynamicPage() returns error that it's not a function
I copied and pasted the sample code directly from
Console error: TypeError: dmAPI.dynamicPageApi(...).isDynamicPage(...).then is not a function
The code in my widget
// Verifies page is a dynamic page - this throws an error
dmAPI.dynamicPageApi().isDynamicPage().then(api => {
console.log(api);
})
// Gets dynamic page data - this works
dmAPI.dynamicPageApi().pageData().then(api => {
console.log(api);
})
What am I missing here?
Best Answers
-
Thank you for catching this! @Russ_Jeffery updated the example - it should work now. Sorry about that :) Thanks Russ!
1 -
As an example of what Arnoldo asked — since it's async, you can do two things:
Wrap in an async function and run:async function run() {
const dynPage = dmAPI.dynamicPageApi(); // check if it's a dynamic page if(dynPage.isDynamicPage()) { //get the data const collectionRowData = await dynPage.pageData();
console.log(collectionRowData) }
}
run();Or you can use it with a then/catch:
// get dynamic page API
const dynPage = dmAPI.dynamicPageApi(); // check if it's a dynamic page
if(dynPage.isDynamicPage()) {
//get the data and resolve with then()
dynPage.pageData().then((data) => {
// page data available here
console.log(data)
}).catch((e) => console.error(e));
}0
Answers
-
Thank you. Do you have suggestions to use that inside of widget?
After adding that directly to my widget, I get the following error
Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
0 -
Hey John,
Can you please confirm that you have wrapped your function with the async keyword?
0