Admin Print Action - 401 from print page after deploy

Having an issue getting a print action setup. I’ve followed the tutorial here: Build an admin print action UI extension and have it working on the dev side. Only major difference is I am targeting “admin.order-index.selection-print-action.render” and my html is different.

Whenever I try to use the print action after deploy, however, I’m getting a 401 response from the print.js route. Is the tutorial outdated and I need authenticate differently? Am I missing a key part of deployment?

Hi @Joseph_Hanks! I scaffolded the print action tutorial with that target and it builds and prints as expected, so the authenticate.admin(request) approach in the print route is still the right one.

A 401 from your print route after deploy likely means the deployed server can’t verify the session token that the print preview sends. authenticate.admin validates that token (a JWT) against your app’s API secret, so the usual cause is the production environment using a different or stale SHOPIFY_API_SECRET / SHOPIFY_API_KEY than the app that’s actually rendering in admin. It could be working under shopify app dev because the CLI injects the correct values for you, but if the deployed host doesn’t have the matching ones it won’t work.

It could also be worth double-checking your application_url points at the host that serves the print route too, and that src stays a relative path like /print?... rather than an absolute URL (see session tokens for how verification works).

If the env vars all line up and it’s still 401ing, share the status, any X-Shopify-Retry-Invalid-Session-Request header, and your src value, I can take a closer look. Thanks!

I think I found the issue: I didn’t setup the sql database like the gcloud tutorial wanted and that caused me to lose data on which store was installed. I’m getting that setup, though through a combination of below and also gcloud taking forever to do anything, I’m still running through it.

As a side note, that tutorial needs some major work. It doesn’t fully separate between Windows and Linux, and even when it does, the first thing command it has you run straight up doesn’t work. I had to replace most of the environment variables with $env:VARIABLE_NAME for anything to work, and there are parts of it that I am troubleshooting because they don’t work as written. Fully could be something funky about my setup, but not this many things.

Unfortunately that didn’t fix it either. Double checked all my gcloud keys and made sure they returned latest.

Error on the print page does give us a X-Shopify-API-Request-Failure-Reauthorize-Url header. src is “/picklist-print?orders=…” leading to that route.