Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
I am trying an experiment and I think I am close to a complete solution. I would like to do the following.
I created a prototype, but the best I could do was satisfy objectives 1-3. I do not know how to satisfy all 4 objectives. Is it possible to satisfy all 4 objectives? If so, what do I need to do?
Details on my prototype:
For my prototype I created an unpublished sales channel app called the ProtoApp. My ProtoApp will use the script_tag.json API endpoint to load a custom javascript file from one of my linux servers. My custom javascript file will add a new <button> element to the header of the webpage. The onclick event of the button will make an ajax call to my ProtoApp . My ProtoApp will make the following call via BASH on Linux
curl -i \ -H "Accept: application/json" \ -H "Content-Type:application/json" \ -H "X-Shopify-Access-Token: mytokenfromshopify" \ -X POST "https://mystore.myshopify.com/admin/api/2019-07/checkouts.json" \ -d @checkout.json
And my checkout.json looks like this
{ "checkout": { "line_items": [ { "variant_id": 11111111111111, "quantity": 2 } ], "applied_discount": { "amount": ###autogen###, "title": "XYZ Promotion", "description": "Promotional item for blackfriday.", "value": ###autogen###, "value_type": "fixed_amount", "non_applicable_reason": null, "applicable": true } } }
Shopify Checkout API will give me a success response. I will find a web_url with a value like https://mystore.myshopify.com/402423011/checkouts/2b3e24742ea6c087ec7c10e7c4117bba in the success response. I send this web_url back to my javascript file and do a location.href = web_url, which causes the customer to go to the checkout page. The customer sees the appropriate discount applied. The customer can continue with checkout process and payment. Everything is perfect.
To my current understanding, the problem with this approach is that in order to use it in a production store, I must publish my app to the market. This means other people other than me will be able to use it. Hence failure to meet the 4th requirement mentioned above.
Based on my research, a private app will not allow me the write_checkout scope, which to my understanding, is necessary for my solution.
Any suggestions on what I can do to satisfy all 4 objectives?
Solved! Go to the solution
This is an accepted solution.
I am afraid there is no way to workaround this and cover for all 4 objectives above.
Thanks for you insight!
When I ready about the Graph QL approach, I seem to see indications of a checkout API:
https://help.shopify.com/en/api/storefront-api/guides/checkout-guide#creating-the-checkout
Do you think that would allow me to cover all four of the requirements?
I think the same constraints would apply, but you can give it a try.
On a second thought, you can publish the app and then within your code limit the usage to just the store you want it to run (check the server the request to your JS originated and exercise the actual functionality only if the domain matches the store or the list of stores you want), but that would look odd/confusing for merchants and I am more than sure Shopify wont certify such an app for publication in the app store.
Thanks again for your insight. You stated the exact reason why I do not want to make a public app. Because I'm under the impression that a public app must be reviewed by Shopify. And I can't see Shopify allowing an app like mine that was meant for only one merchant store to be publicly listed.
So I took another look at https://help.shopify.com/en/api/storefront-api/guides/checkout-guide#creating-the-checkout . It says the prerequisite is to have access to StoreFront API. And the prerequisite to StoreFront API is to create either a private app or a public app. And I already ran into the problem that private does not offer the write_checkout scope. And we are already saying that the public app will likely be rejected.
So is that it? What I'm asking for is impossible?
Actually, can I keep my prototype as an unpublished sales channel app. Then from my Shopify Partners account, some how gain access to my real shopify store. Then install my prototype to my real shopify store?
This is an accepted solution.
Agh...that is so irritating! You're right, because my shopify partner account only allows me to install apps on development stores....
This is frustrating....why is it so difficult to share an app that requires write_checkouts scope with only one other store in the real world? I just don't get the reason behind that....