Detecting app embed blocks

lokki54
Shopify Partner
47 0 10

Hello. Can someone explain in more detail about the Detecting app embed blocks?

https://shopify.dev/apps/online-store/theme-app-extensions/extensions-framework#detecting-app-embed-...

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?

 

Theme_app_extensions_framework.png

Replies 5 (5)

GrIntegrations
Shopify Partner
4 1 1

yash100ni
Shopify Partner
7 0 3
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`
  }
}
robertnguyen
Shopify Partner
2 0 0

I have the app enabled in the theme customization. but my json['current']['blocks'] nil , you can help me

Lookfy
Shopify Partner
3 0 0

Can you explain more about input data
checkAppActivated (data)

 

Thanks

Lookfy - Lookbook & Gallery. The ultimate solution for creating captivating lookbooks and product galleries.

Lookfy
Shopify Partner
3 0 0

I think It's ID. ( Red Box )

Lookfy_0-1693304044230.png

 

Lookfy - Lookbook & Gallery. The ultimate solution for creating captivating lookbooks and product galleries.