What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: How to store external API Key with Theme Extensions

How to store external API Key with Theme Extensions

sercanov
Tourist
4 1 2

Hi, I'm developing an embedded app which requires access to our external API ( Meshkraft ) from storefront via a token. I've successfully implemented this behavior with ScriptTag after first install but Shopify App Review Team suggested me that I implement Theme Extensions as ScriptTags will eventually deprecate. 

I was storing token in ScriptTags like below, then meshkraft-shopify.js in Storefront would access to that token easily.

 

const requestBody = {
    script_tag: {
      event: "onload",
      src: `https://unpkg.com/meshkraft-viewer/dist/meshkraft-shopify.min.js?token=${token}`
      },
    },
 

 

 

Now I'm trying to save and access this shop-wide token in App Block with Theme Extensions. I guess there's no way to query external database, it seems I need to store it in Private Metafields but as far as I know, private metafields cant be accessed in .liquid files. So, I'm stuck with ScriptTags. 

Basically,

1. I need to register the Shopify shop to our external API platform after app installation [ In Admin App ]

2. Get the API token [ In Admin App ]

3. Save it somewhere [ In Admin App ] ( It's not a public token so I have no security concerns ) 

4. Fetch and use it in Theme Extension App Block. [ In Storefront ]

 

Also, I'd happily continue to use ScriptTag's if possible. It's much easier to inject single javascript file to Storefront. This script basically gets Product GID, API token and adds an AR Button to Product page. When pressed, opens an AR session with the 3D model fetched from our server.

 

Any suggestions?

 

 

Replies 4 (4)

miguel34
Shopify Partner
3 0 1

I have a somewhat similar issue with app embeds.

Was using previously script tags to load a custom-defined javascript per store. The JS is generated upon account registration, is stored in AWS S3 and served via cloudfront CDN. Now I need to change to support both app embeds and script tags.

But I can not find information on how to load this remote JS.

Not applicable

@miguel34  have figure out the solution? 

miguel34
Shopify Partner
3 0 1

Hi, I have not find a solution yet @Anonymous 

Not applicable

@miguel34  thanks for the update i am working on the right way with app meta field data app own but i am not able to access those data. 
 may i think this solution will work but this was does not work for me on theme app extenstion https://community.shopify.com/c/shopify-apis-and-sdks/want-to-store-privatemetafields-with-shopify-r...