Created
May 8, 2023 15:17
-
-
Save r3trosteve/6547c6accb4c6963568d8912aa441879 to your computer and use it in GitHub Desktop.
Shopify Hello World plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', async () => { | |
const AppBridge = window['app-bridge']; | |
const { createApp } = AppBridge; | |
const { authenticatedFetch } = AppBridge.Utils; | |
const app = createApp({ | |
apiKey: 'YOUR_SHOPIFY_API_KEY', | |
shopOrigin: 'YOUR_SHOPIFY_SHOP_ORIGIN', | |
}); | |
document.getElementById('getPersonalizedHello').addEventListener('click', async () => { | |
const response = await authenticatedFetch(app)('/admin/api/2022-04/shop.json'); | |
const data = await response.json(); | |
const welcomeMessage = document.getElementById('welcomeMessage'); | |
welcomeMessage.textContent = `Hello, ${data.shop.shop_owner}! Welcome to our Shopify App!`; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment