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: Deployment to Heroku: Missing Shopify API Key

Solved

Deployment to Heroku: Missing Shopify API Key

Mat_Brummitt
Shopify Partner
60 2 16

Hi all,

 

Incredibly frustrating, i'm following the Shopify docs for deploying an app to Heroku for an app which was scaffolded and build with the Shopify CLI.

 

I'm following these docs:

https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-heroku

 

And more generally for deploying to a hosting service:

https://shopify.dev/docs/apps/launch/deployment/deploy-web-app/deploy-to-hosting-service

 

Initially the app would just crash immediately and a Heroku error would display. After reading other people's issues with this, it turned out to be that the docs don't actually tell you to set up a HOST env variable on Heroku.  Literally no mention of the HOST env variable whatsoever in the docs, so I added it via Heroku web admin, and suddenly the app no longer crashes! Hurray!

 

However, the current issue I have is that I now see a Shopify error as follows:

Mat_Brummitt_0-1726913479107.png

Additionally the logs show the following:

remote: Building the frontend app without an API key. The frontend build will not run without an API key. Set the SHOPIFY_API_KEY environment variable when running the build command.

 

I've followed the docs completely I just don't understand what to do at this point. How do I "Set the SHOPIFY_API_KEY environment variable when running the build command" when this is all supposed to be handled by the CLI's that are being used according to the docs?

 

Note: calling "shopify app env show" returns the expected environment variables and values.

 

Thanks for any advice

 

Mat

Accepted Solution (1)

sherpabot
Shopify Partner
40 3 4

This is an accepted solution.

Did you set the variables in your heroku app via the CLI or the dashboard > settings > config vars? 

Screenshot 2024-09-21 at 11.46.50 AM.png

heroku config:set -a <my-app-name> \
    SHOPIFY_APP_URL=https://<app-container>.herokuapp.com \
    SHOPIFY_API_KEY=<SHOPIFY_API_KEY> \
    SHOPIFY_API_SECRET=<SHOPIFY_API_SECRET> \
    SCOPES=<SCOPES>



in your heroku tml file you can also add it there:

build:
  docker:
    web: Dockerfile
  config:
    SHOPIFY_API_KEY: <SHOPIFY_API_KEY>

 

 



View solution in original post

Replies 2 (2)

sherpabot
Shopify Partner
40 3 4

This is an accepted solution.

Did you set the variables in your heroku app via the CLI or the dashboard > settings > config vars? 

Screenshot 2024-09-21 at 11.46.50 AM.png

heroku config:set -a <my-app-name> \
    SHOPIFY_APP_URL=https://<app-container>.herokuapp.com \
    SHOPIFY_API_KEY=<SHOPIFY_API_KEY> \
    SHOPIFY_API_SECRET=<SHOPIFY_API_SECRET> \
    SCOPES=<SCOPES>



in your heroku tml file you can also add it there:

build:
  docker:
    web: Dockerfile
  config:
    SHOPIFY_API_KEY: <SHOPIFY_API_KEY>

 

 



Mat_Brummitt
Shopify Partner
60 2 16

Thank you, thank you thank you!!!

 

It was updating the heroku.yml file that made it work for me:

config:
    SHOPIFY_API_KEY: <SHOPIFY_API_KEY>

I can't understand why this isn't documented on the page which describes how to deploy to Heroku!

 

Anyway thanks so much again, it's amazing to finally see my app hosted in a production environment and ready for deployment after so much hard work!

 

Mat