Skip to content

Instantly share code, notes, and snippets.

@phawk
Created August 23, 2019 16:17
Show Gist options
  • Save phawk/5e47aef501135001c0e443f68a1d7826 to your computer and use it in GitHub Desktop.
Save phawk/5e47aef501135001c0e443f68a1d7826 to your computer and use it in GitHub Desktop.
Shopify install lambda
exports.handler = async (event, context) => {
const shop = event.queryStringParameters.shop
const redirectUri = event.queryStringParameters.redirect
const apiKey = process.env.SHOPIFY_API_KEY
const scopes="read_content,write_content,read_products,read_themes,write_themes"
if (shop) {
const installUrl = 'https://' + shop +
'/admin/oauth/authorize?client_id=' + apiKey +
'&scope=' + scopes +
'&redirect_uri=' + redirectUri
return {
statusCode: 200,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
redirectTo: installUrl
})
}
}
return {
statusCode: 400,
body: "Missing shop parameter. Please add ?shop=your-development-shop.myshopify.com to your request"
}
}
@lenowng
Copy link

lenowng commented Nov 11, 2020

line 13 can be written as, instead:

    return {
      statusCode: 301,
      headers: { 'Location': installUrl },
      body: ''
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment