Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant connect store to hydrogen #2419

Open
tassawarr opened this issue Aug 9, 2024 · 20 comments
Open

cant connect store to hydrogen #2419

tassawarr opened this issue Aug 9, 2024 · 20 comments

Comments

@tassawarr
Copy link

What is the location of your example repository?

No response

Which package or tool is having this issue?

CLI

What version of that package or tool are you using?

CMD

What version of Remix are you using?

No response

Steps to Reproduce

following this documentation im stuck on store connection.

https://shopify.dev/docs/storefronts/headless/hydrogen/getting-started#step-1-create-a-new-hydrogen-storefront

Expected Behavior

it must connect the shopify store to my local hydrogen storefront: the authentication issues comes up.

Actual Behavior

this is what im experiencing right now while connecting to store. i tried finding CLI > SHOPIFY CLI but couldnt find it.

Screenshot 2024-08-09 184007

@michenly
Copy link
Contributor

michenly commented Aug 9, 2024

I am unable to re-produce this on my end, and this looks to be permission related and its impossible for me to verify.

@graygilmore do you know what settings is missing that might trigger this response?

Pass that I would suggest that you contact your Shopify customer service who have access to your account to check for the proper permission.

@tassawarr
Copy link
Author

tassawarr commented Aug 9, 2024

thanks @michenly for your reply, i've tried every single permission inside headless app > storefront api settings. but the error stands.
guide me how to use CLI. as im using Windows CMD and macOS terminal. which one should i use?

that image says.

 The Admin GraphQL API responded unsuccessfully with errors:                 
                                                                              
  [                                                                           
    {                                                                         
      "message": "Access denied for hydrogenStorefronts field. Required       
  access: Request must be initiated from the Shopify CLI and user must have   
  full access to apps or access to the Hydrogen channel.",                    
      "locations": [                                                          
        {                                                                     
          "line": 3,                                                          
          "column": 5                                                         
        }                                                                     
      ],                                                                      
      "path": [                                                               
        "hydrogenStorefronts"                                                 
      ],                                                                      
      "extensions": {                                                         
        "code": "ACCESS_DENIED",                                              
        "documentation": "https://shopify.dev/api/usage/access-scopes",       
        "requiredAccess": "Request must be initiated from the Shopify CLI     
  and user must have full access to apps or access to the Hydrogen channel."  
      }                                                                       
    }                                                                         
  ]                                                                           
                                                                              
  Request ID: b8468db5-e0b6-4f3c-9bb9-975bd1c09e2a-1723221772                 
                                                                              
                                                                              
  To investigate the issue, examine this stack trace:                         
    at makeRequest (Users/horizon/AppData/Roaming/npm/node_modules/@shopify/  
    cli/dist/chunk-UBCH575K.js:50408)                                         
    at processTicksAndRejections (node:internal/process/task_queues:95)       
    at async debugLogResponseInfo (Users/horizon/AppData/Roaming/npm/node_mo  
    dules/@shopify/cli/dist/chunk-UBCH575K.js:50444)                          
    at (Users/horizon/AppData/Roaming/npm/node_modules/@shopify/cli/dist/chu  
    nk-U2PN6QZ2.js:4671)                                                      
    at (Users/horizon/AppData/Roaming/npm/node_modules/@shopify/cli/dist/chu  
    nk-T4Y7NDNJ.js:42849)                                                     
    at async adminRequest (Users/horizon/AppData/Roaming/npm/node_modules/@s  
    hopify/cli/dist/chunk-K7KD247K.js:156914)                                 
    at async getStorefronts (Users/horizon/AppData/Roaming/npm/node_modules/  
    @shopify/cli/dist/chunk-K7KD247K.js:156973)                               
    at async linkStorefront (Users/horizon/AppData/Roaming/npm/node_modules/  
    @shopify/cli/dist/chunk-K7KD247K.js:163050)                               
    at async runLink (Users/horizon/AppData/Roaming/npm/node_modules/@shopif  
    y/cli/dist/chunk-K7KD247K.js:163014)                                      
    at run (Users/horizon/AppData/Roaming/npm/node_modules/@shopify/cli/dist  
    /chunk-K7KD247K.js:163002) 

@tassawarr
Copy link
Author

also, when i setup the custom storefront it doesnt gave me the .env file include store token or store url as it seems to be including on first setup

@graygilmore
Copy link
Contributor

It sounds like your particular account does not have access to Apps or the Hydrogen sales channel. It's not about the access that the channel has, it's about the access that you have to the channel. The link that the error message is providing is misleading.

If you can confirm that the account you're logging in with has access to apps (you can test this by logging in with that account and navigating to the Hydrogen sales channel in the admin) we can dig into the logs to see what's up.

@dd-anish
Copy link

I have some questions for this, the same error was faced by us ( me and @KedarMalapDev ), but after some research we did found the solution for this. But before telling you the solution, let me know the answers for the questions:

  1. Do your store has Hydrogen Sales Channel Access (I believe it is not available for Free Plans)
  2. Since, you mentioned you have Headless Channel then the command npx shopify hydrogen env pull will give you the error you are facing now. So do your project structure has env credentials? If yes then are they defined?

@HeisUser
Copy link

HeisUser commented Sep 9, 2024

I have this kind of same Error on Linking Mock.shop by "npx shopify hydrogen link" or "h2 link"
My GitHub is https://github.com/HeisUser/store-hydrogen-remix-js.git

I was according this Official Guide https://shopify.dev/docs/storefronts/headless/hydrogen/getting-started to linking my Headless Storefront to Mock.shop of Hydrogen. Which is the Step 3 as https://shopify.dev/docs/storefronts/headless/hydrogen/getting-started#step-3-link-your-hydrogen-project-to-shopify and get error by npx shopify hydrogen link command.
Step 3 means simply run npx shopify hydrogen link command to automatically linking and create .env file and the APIs values of .env will be automatically added.
But I still get Error Screenshot as
Image

$ npm list screenshot as
Image

$ npm list -g screenshot as
Image

@graygilmore
Copy link
Contributor

I have this kind of same Error on Linking Mock.shop by "npx shopify hydrogen link" or "h2 link"

@HeisUser what are you trying to do? Have you already created a Hydrogen storefront in your Shopify admin?

@HeisUser
Copy link

HeisUser commented Sep 9, 2024

I have this kind of same Error on Linking Mock.shop by "npx shopify hydrogen link" or "h2 link"

@HeisUser what are you trying to do? Have you already created a Hydrogen storefront in your Shopify admin?

Please read my first comment again, because I'd edited it.
Where is the Hydrogen Storefront?
Please see red and orange arrows on my screenshot as
Image

@graygilmore
Copy link
Contributor

@HeisUser the Hydrogen CLI commands only relate to storefronts in the Hydrogen channel, not the Headless channel. Make sure the user you are authenticating over the CLI with is the same user that has access to the Hydrogen channel in the admin.

@HeisUser
Copy link

HeisUser commented Sep 9, 2024

@HeisUser the Hydrogen CLI commands only relate to storefronts in the Hydrogen channel, not the Headless channel. Make sure the user you are authenticating over the CLI with is the same user that has access to the Hydrogen channel in the admin.

Noted.. Anyways how to linking to Headless Channel?

@graygilmore
Copy link
Contributor

Noted.. Anyways how to linking to Headless Channel?

This is not possible and isn't planned.

@HeisUser
Copy link

Noted.. Anyways how to linking to Headless Channel?

This is not possible and isn't planned.

I'm not understanding.. R u mean Headless channel hasn't to be used and ready yet?

@graygilmore
Copy link
Contributor

You cannot link a local Hydrogen storefront to something in the Headless channel. You can only link a Hydrogen storefront to something in the Hydrogen channel.

@HeisUser
Copy link

HeisUser commented Sep 10, 2024

You cannot link a local Hydrogen storefront to something in the Headless channel. You can only link a Hydrogen storefront to something in the Hydrogen channel.

I know the Hydrogen app (paid) on Sales Channels is not allowed to be linking the Storefronts in development mode.

Anyways, How to use & linking Headless app on Sales Channels ?
I'd followed the setup guides as follows:

@graygilmore
Copy link
Contributor

Anyways, How to use & linking Headless app on Sales Channels ?

You cannot link a local Hydrogen storefront to the Headless sales channel.

The only thing you can link is a Hydrogen storefront to the Hydrogen sales channel. If you plan on building with Hydrogen and hosting on Oxygen then uninstall the Headless sales channel. If you plan on building with Hydrogen and hosting on something other than Oxygen then you can keep the Headless sales channel but you won't be able to use some of the features of the CLI (like link and deploy).

@HeisUser
Copy link

Anyways, How to use & linking Headless app on Sales Channels ?

You cannot link a local Hydrogen storefront to the Headless sales channel.

The only thing you can link is a Hydrogen storefront to the Hydrogen sales channel. If you plan on building with Hydrogen and hosting on Oxygen then uninstall the Headless sales channel. If you plan on building with Hydrogen and hosting on something other than Oxygen then you can keep the Headless sales channel but you won't be able to use some of the features of the CLI (like link and deploy).

Thank you for your guides.

@fabianwohlfart
Copy link

Just to clarify.
I wanted to test the Hydrogen and Oxygen integrations.
Therefor I created a test store in my partner dashboard and populated it with some data.
It is not possibly to use Hydrogen and Oxygen with a test store?

I managed to manually add the following to the .env

SESSION_SECRET=
PUBLIC_STORE_DOMAIN=
PUBLIC_STOREFRONT_ID=
PUBLIC_STOREFRONT_API_TOKEN=
PRIVATE_STOREFRONT_API_TOKEN=
PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID=
PUBLIC_CUSTOMER_ACCOUNT_API_URL=

and got my customer redirect working with Ngrok.

Yet it's not possible to deploy with Oxygen with a test store?

@graygilmore
Copy link
Contributor

@fabianwohlfart Oxygen is not currently available for development stores.

@dd-anish
Copy link

dd-anish commented Sep 25, 2024

@graygilmore I guess we can link our local hydrogen store to our Shopify Backend using Headless Channel. Like, I have connected my local hydrogen project to my shopify backend and rendered the store's product in it.

@HeisUser the Hydrogen Sales channel is for paid plan through which we are able to connect local hydrogen project to it and have a Oxygen deployment with it (Paid feature of hydrogen sales channel). Initially, I did face these issues but later was able to understand few stuff and connect my Shopify Backend to the local hydrogen project.

After successfully seeing the Mock.shop using the shopify hydrogen dev command when you use npx shopify hydrogen link and npx shopify hydrogen env pull commands, you will encounter the ACCESS ERROR as seen in above comments since, we are trying to use Hydrogen Sales Channel which is the paid one and use its functionality. Hydrogen Getting Started

So, first let's understand what Headless Development of Shopify provides us.

Sales Channel

  • Hydrogen Sales Channel: Paid One (Free Hosting with Oxygen)

  • Headless Sales Channel: Free plan which provides you two APIs and not limited to Hydrogen—you can "bring your own stack" (BYOS) and use any tools you prefer.

    • Storefront API: Access product, collection, checkout, and order data from Shopify.

    • Customer Account API: Manages customer accounts, including authentication, registration, and account management features.

      Image

APIs Usage

  • Hydrogen is primarily focused on using the Storefront API for building custom storefronts, with the Customer Account API being optional depending on the needs of the project.
  • Headless generally uses both the Storefront API for e-commerce functionalities and the Customer Account API for handling customer accounts and authentication.

Using the API Tokens

  • Install the Headless App in your Shopify store.
  • Inside the app, navigate to the Storefront API section.
  • Copy the Public Access Token and paste it into the .env file as PUBLIC_STOREFRONT_API_TOKEN.

.env file

PUBLIC_STOREFRONT_API_TOKEN = your-public-access-token
PUBLIC_STOREFRONT_API_VERSION = latest-api-version # I Used 2024-01
PUBLIC_STORE_DOMAIN = store-name.myshopify.com
  • Use npm run dev and this will connect your project to the specified Shopify store, and you’ll be ready to start development!

Now if you want to have login and registration functionality, you need to use Customer Account API of headless channel. However, when using the Customer Account API from the Headless channel in a Hydrogen project, we may encounter the following error.

Image

This error indicates that we need access to the Hydrogen channel to enable additional functionality, such as user accounts.

Solution: Using Ngrok [Docs]

  • If you want to access the customer account API without using the Hydrogen channel, you can set up Ngrok for local development. You'll also need to make some updates in the Headless Sales Channel, specifically under the customer account API section for application setup.
  • Refer this link
  • Note: Use Port 3000 to start tunnel in ngrok as your hydrogen projects uses that port.

Final .env File

# Session secret key for securing cookies and sessions
SESSION_SECRET = "your-session-secret"

# Storefront ID
PUBLIC_STOREFRONT_ID = "your-storefront-id"

# Storefront API tokens
PUBLIC_STOREFRONT_API_TOKEN = "your-public-storefront-api-token"
PRIVATE_STOREFRONT_API_TOKEN = "your-private-storefront-api-token"

# Storefront API version
PUBLIC_STOREFRONT_API_VERSION = "your-api-version" # 2024-01

# Store domain
PUBLIC_STORE_DOMAIN = "your-store-domain.myshopify.com"

# Customer Account API credentials
PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID = "your-customer-account-api-client-id"
PUBLIC_CUSTOMER_ACCOUNT_API_URL = "https://shopify.com/your-shop-id"

So, that's it from my side. Let me know if I did any mistake in this. Happy to correct it and learn from you all. Thanks!

@HeisUser
Copy link

@graygilmore I guess we can link our local hydrogen store to our Shopify Backend using Headless Channel. Like, I have connected my local hydrogen project to my shopify backend and rendered the store's product in it.

@HeisUser the Hydrogen Sales channel is for paid plan through which we are able to connect local hydrogen project to it and have a Oxygen deployment with it (Paid feature of hydrogen sales channel). Initially, I did face these issues but later was able to understand few stuff and connect my Shopify Backend to the local hydrogen project.

After successfully seeing the Mock.shop using the shopify hydrogen dev command when you use npx shopify hydrogen link and npx shopify hydrogen env pull commands, you will encounter the ACCESS ERROR as seen in above comments since, we are trying to use Hydrogen Sales Channel which is the paid one and use its functionality. Hydrogen Getting Started

So, first let's understand what Headless Development of Shopify provides us.

Sales Channel

* **[Hydrogen Sales Channel](https://shopify.dev/docs/storefronts/headless/hydrogen/fundamentals)**: Paid One (Free Hosting with Oxygen)

* **[Headless Sales Channel](https://shopify.dev/docs/storefronts/headless/bring-your-own-stack)**: Free plan which provides you [two APIs](https://shopify.dev/docs/storefronts/headless/bring-your-own-stack#manage-api-permissions) and not limited to Hydrogen—you can "bring your own stack" (BYOS) and use any tools you prefer.
  
  * **Storefront API:** Access product, collection, checkout, and order data from Shopify.
  * **Customer Account API:** Manages customer accounts, including authentication, registration, and account management features.
    ![Image](https://github.com/user-attachments/assets/02f5fcd5-f501-4281-a72e-c49f5b2409a2)

APIs Usage

* **Hydrogen** is primarily focused on using the **Storefront API** for building custom storefronts, with the **Customer Account API** being optional depending on the needs of the project.

* **Headless** generally uses both the **Storefront API** for e-commerce functionalities and the **Customer Account API** for handling customer accounts and authentication.

Using the API Tokens

* Install the **Headless App** in your Shopify store.

* Inside the app, navigate to the **Storefront API** section.

* Copy the **Public Access Token** and paste it into the `.env` file as `PUBLIC_STOREFRONT_API_TOKEN`.

.env file

PUBLIC_STOREFRONT_API_TOKEN = your-public-access-token
PUBLIC_STOREFRONT_API_VERSION = latest-api-version # I Used 2024-01
PUBLIC_STORE_DOMAIN = store-name.myshopify.com

* Use `npm run dev` and this will connect your project to the specified Shopify store, and you’ll be ready to start development!

Now if you want to have login and registration functionality, you need to use Customer Account API of headless channel. However, when using the Customer Account API from the Headless channel in a Hydrogen project, we may encounter the following error.

Image

This error indicates that we need access to the Hydrogen channel to enable additional functionality, such as user accounts.

Solution: Using Ngrok [Docs]

* If you want to access the customer account API without using the Hydrogen channel, you can set up Ngrok for local development. You'll also need to make some updates in the Headless Sales Channel, specifically under the customer account API section for application setup.

* Refer this [link](https://shopify.dev/docs/storefronts/headless/building-with-the-customer-account-api/hydrogen#step-1-set-up-a-public-domain-for-local-development)

* **Note:** Use Port 3000 to start tunnel in ngrok as your hydrogen projects uses that port.

Final .env File

Session secret key for securing cookies and sessions

SESSION_SECRET = "your-session-secret"

Storefront ID

PUBLIC_STOREFRONT_ID = "your-storefront-id"

Storefront API tokens

PUBLIC_STOREFRONT_API_TOKEN = "your-public-storefront-api-token"
PRIVATE_STOREFRONT_API_TOKEN = "your-private-storefront-api-token"

Storefront API version

PUBLIC_STOREFRONT_API_VERSION = "your-api-version" # 2024-01

Store domain

PUBLIC_STORE_DOMAIN = "your-store-domain.myshopify.com"

Customer Account API credentials

PUBLIC_CUSTOMER_ACCOUNT_API_CLIENT_ID = "your-customer-account-api-client-id"
PUBLIC_CUSTOMER_ACCOUNT_API_URL = "https://shopify.com/your-shop-id"

So, that's it from my side. Let me know if I did any mistake in this. Happy to correct it and learn from you all. Thanks!

Thank you for the useful information. Let me try again.

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

No branches or pull requests

6 participants