Shopify/lighthouse-ci-action

Getting 401 error but can run on Command line

kevindiamond opened this issue · 12 comments

I am getting the following issue when running it, but confirmed the app token works when running it on the command line.

`Configuring shopify CLI
Will run Lighthouse CI on https://***

Creating development theme
✗ Please login again with shopify login

Configuring Lighthouse CI
Fetching product handle
There's been an error when querying the API

curl: (22) The requested URL returned error: 401 `

➜ curl -X POST \ https://{domain}.myshopify.com/admin/api/2022-04/graphql.json \ -H 'Content-Type: application/graphql' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d ' { products(first: 5) { edges { node { id handle } } pageInfo { hasNextPage } } } ' {"data":{"products":{"edges":[{"node":{"id":"gid:\/\/shopify\/Product\/6967023468732","handle":"spank-me-black-lace-teddy"}},{"node":{"id":"gid:\/\/shopify\/Product\/6967185932476","handle":"naughty-night-shift-nurse-costume"}},{"node":{"id":"gid:\/\/shopify\/Product\/6967188979900","handle":"plus-size-sheer-seduction-robe-set"}},{"node":{"id":"gid:\/\/shopify\/Product\/6967203299516","handle":"plus-size-blush-touch-chemise-set"}},{"node":{"id":"gid:\/\/shopify\/Product\/6967203463356","handle":"plus-size-relentless-rosebud-chemise-set"}}],"pageInfo":{"hasNextPage":true}}},"extensions":{"cost":{"requestedQueryCost":7,"actualQueryCost":7,"throttleStatus":{"maximumAvailable":2000.0,"currentlyAvailable":1993,"restoreRate":100.0}}}}%

This is how we do the request internally. You're getting a 401 which means that the token is invalid.

Is your access_token set properly? Are you using app_password (the deprecated option)?

https://github.com/Shopify/lighthouse-ci-action/blob/main/entrypoint.sh#L68-L73

Did the read_products permission grant?

I have given the permissions for read_products and write_themes and I am using the access_token generated when setting the API. I then used same token when I tested the graphql query. Other thoughts on what might not work? I use secrets.SHOP_ACCESS_TOKEN and have it set in the repos' secrets.

Only thing I could think of is sensitivity on whitespace? Something like the secret has a trailing new line (\n) at the end?

Nope... just resaved all of the secrets and ensured no whitespace issues. Any other ideas? Or anyway I can test the script locally to see why it might be having an issue?

You can try to run entrypoint.sh by setting all the environment variables manually beforehand:

From the logs you pasted, it looks like the error you get comes from this code branch:

Which would imply that one of those two branches returned an API response with a non-empty errors array.

You might want to paste the entire contents of $out to see what happens with the CURL request.

What's the content of your workflow file?

I too faced this issue.
I would like to run locally as mentioned, How should I run it?

I too faced this issue.

Self solved.
I think there were no valid products in my development store.
never mind.

To get consistent results from Lighthouse, you should populate your store using the test product csv. The store should have no other collections, products, or variants. This file contains the same data that is used to test themes before they are accepted into the Shopify Theme Store.

Same here, I'm getting this error for lighthouse ci

Configuring shopify CLI
Will run Lighthouse CI on https://***
==============================

Creating development theme
✗ Please login again with shopify login
==============================

Configuring Lighthouse CI
Fetching product handle
There's been an error when querying the API

Run shopify/lighthouse-ci-action@***.0 with: access_token: ***} store: *** password: *** LHCI_GITHUB_APP_TOKEN: *** theme_root: . lhci_min_score_performance: 0.6 lhci_min_score_accessibility: 0.9 /usr/bin/docker run --name e0406087e944***5***9dc[2](https://github.com/github-username/HK-new-shopify-theme/actions/runs/3653496764/jobs/6173027434#step:4:2)9966068c9005_***a0ff8 --label 290506 --workdir /github/workspace --rm -e "INPUT_ACCESS_TOKEN" -e "INPUT_STORE" -e "INPUT_PASSWORD" -e "INPUT_LHCI_GITHUB_APP_TOKEN" -e "INPUT_PRODUCT_HANDLE" -e "INPUT_COLLECTION_HANDLE" -e "INPUT_THEME_ROOT" -e "INPUT_LHCI_GITHUB_TOKEN" -e "INPUT_LHCI_MIN_SCORE_PERFORMANCE" -e "INPUT_LHCI_MIN_SCORE_ACCESSIBILITY" -e "INPUT_APP_ID" -e "INPUT_APP_PASSWORD" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/HK-new-shopify-theme/HK-new-shopify-theme":"/github/workspace"

I'm getting a similar error. My setup could be causing the issue. This is a staging branch in GitHub connected to a live store as a non-published theme. The staging theme is a carbon copy of the production theme.

I presume the app works for non-published themes? And Lighthouse CI as well?

I first tried the theme connected to a development store, but because of the many metafields I created, it looks for those metafields and showed missing errors, that was causing some issues I thought. So instead I connected it to the live store as unpublished.

Other wise I followed all the steps. Would be really great if I could get some support on this. Or some guidance for things to try. Thanks!

with: access_token: ***} store: *** lhci_github_app_token: *** theme_root: . lhci_min_score_performance: 0.6 lhci_min_score_accessibility: 0.9 /usr/bin/docker run --name b5d6262db8515fd[3](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:3)7[4](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:4)b78a0aca0d97f4320e4_4edd8[5](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:5) --label 4b5d[6](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:6)2 --workdir /github/workspace --rm -e "INPUT_ACCESS_TOKEN" -e "INPUT_STORE" -e "INPUT_LHCI_GITHUB_APP_TOKEN" -e "INPUT_PASSWORD" -e "INPUT_PRODUCT_HANDLE" -e "INPUT_COLLECTION_HANDLE" -e "INPUT_THEME_ROOT" -e "INPUT_PULL_THEME" -e "INPUT_LHCI_GITHUB_TOKEN" -e "INPUT_LHCI_MIN_SCORE_PERFORMANCE" -e "INPUT_LHCI_MIN_SCORE_ACCESSIBILITY" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_ENVIRONMENT" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e "ACTIONS_RESULTS_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/smak-dab-mustard/smak-dab-mustard":"/github/workspace" 4b5d62:62db8515fd3[7](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:7)4b7[8](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:8)a0aca0d[9](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:10)7f43[20](https://github.com/superfein/smak-dab-mustard/actions/runs/7907300992/job/21584193133#step:4:21)e4 ============================== Configuring shopify CLI Will run Lighthouse CI on https://*** ============================== Creating development theme ╭─ error ──────────────────────────────────────────────────────────────────────╮ │ │ │ [401] API request unauthorized error │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯

==============================
Configuring Lighthouse CI
Fetching product handle
There's been an error when querying the API

curl: (22) The requested URL returned error: 401

I should mention, I got similar errors with my development store, with those missing metafields printing. I assumed it was because of that. But I wonder, if I'm a collaborator on the live store, is that an issue? Do I need to be logged in as the owner?

Since this is performance-related, I should also mention that this Chrome Extension no longer works [https://shopify.dev/docs/themes/tools/theme-inspector] and hasn't been updated since 2021. It seems odd to me that it's still listed in the docs.