Hello. Can someone explain in more detail about the Detecting app embed blocks?
An app block is given a unique ID - Is this ID unique for every store and given to block once for a lifetime or is this ID changed in every installation?
Hello. Can someone explain in more detail about the Detecting app embed blocks?
An app block is given a unique ID - Is this ID unique for every store and given to block once for a lifetime or is this ID changed in every installation?
Hi,
You can make a request to API as follow:
https://{{shop}}/admin/themes/{{active-theme-id}}/assets.json?asset[key]=config/settings_data.json
and parse content. You should find it in âblocksâ section
export async function checkAppActivated (data) {
console.log(âcheck app Activatedâ)
var session = data.res.locals.shopify.session;
const clientRes = new shopify.api.clients.Rest({ session });
var response
try {
response = await clientRes.get({
path: âthemesâ,
query: { role: âmainâ },
});
} catch (e) {
console.log(${e} session-info ${session});
}
var themeID = response.body.themes[0].id;
// get existing theme.liquid code
var response2
try {
response2 = await clientRes.get({
path: themes/${response.body.themes[0].id}/assets,
query: {
asset: { key: âconfig/settings_data.jsonâ },
},
});
} catch (e) {
console.log(${e} session-info ${session});
}
// console.log(response2.body.asset.value);
var themeCode = response2.body.asset.value;
if (!themeCode) return false
var json
try {
json = JSON.parse(themeCode)
} catch (error) {
console.log(âerrorâ, error)
}
if (!json.current.blocks) return false
const typeSuffix = blocks/app-embed/6b835701-24aa-464a-b23a-f9592b0522cc
const embedBlock = Object.entries(json.current.blocks).find(([id, info]) => {
return info.type.endsWith(typeSuffix) && !info.disabled
})
// if app is not activated then send activation link
var Actiavted = !!embedBlock
if (Actiavted) {
return ${Actiavted};
}
else {
var shop = session.shop;
return https://${shop}/admin/themes/${themeID}/editor?context=apps&appEmbed=6b835701-24aa-464a-b23a-f9592b0522cc%2Fapp-embed
}
}
I have the app enabled in the theme customization. but my json[âcurrentâ][âblocksâ] nil , you can help me
Can you explain more about input data
checkAppActivated (data)
Thanks