How can I allow Checkout UI Extension to send request to Admin API or my personal server api?

Solved

How can I allow Checkout UI Extension to send request to Admin API or my personal server api?

TuanDangA
Shopify Partner
17 0 7

hi yall, as the title said, when I want to send request using fetch to admin API or my server API, It gives me back "Uncaught (in promise) NetworkAccessDeniedError: permission to use fetch() must be specified under [capabilities] with flag "network_access = true"; this can be done within your extension's configuration. View the docs for more information:". Even though I have added the network_access = true in the extension Config file and check the nable network access in checkout UI extensions box in shopify partner, nothing changed. Can anyone help me out here? any help would be deeply appreciated

Accepted Solution (1)
SBD_
Shopify Staff
1829 272 417

This is an accepted solution.

Hey @cvargas31 

 

Glad to hear it! The Admin API should only be hit from a server environment to keep keys secure. So you'll need to proxy the request through your app. Alternatively, consider storing the data in a metafield (if possible). From the docs:

 

Instead of fetching data with an external network call, consider retrieving the data from a metafield. Your app may be able to use the Admin API to write metafields on the shop, product, or customer ahead of checkout.

Retrieving data from metafields during checkout is faster since it won't introduce an external network call. This allows you to rely on Shopify for the uptime, scaling, and durability of the data storage.

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 5 (5)

SBD_
Shopify Staff
1829 272 417

Hey @TuanDangA 

 

Have you tried restarting/reinstalling? Can I see your config file please. Also, what's your app ID?

Scott | Developer Advocate @ Shopify 

TuanDangA
Shopify Partner
17 0 7

Thanks, Scott for replying, I have made the network denied error by restarting, but not when I fetch adminAPI, it returns a cors error. Can you help me with that?

SBD_
Shopify Staff
1829 272 417

This is an accepted solution.

Hey @cvargas31 

 

Glad to hear it! The Admin API should only be hit from a server environment to keep keys secure. So you'll need to proxy the request through your app. Alternatively, consider storing the data in a metafield (if possible). From the docs:

 

Instead of fetching data with an external network call, consider retrieving the data from a metafield. Your app may be able to use the Admin API to write metafields on the shop, product, or customer ahead of checkout.

Retrieving data from metafields during checkout is faster since it won't introduce an external network call. This allows you to rely on Shopify for the uptime, scaling, and durability of the data storage.

Scott | Developer Advocate @ Shopify 

cvargas31
Shopify Partner
1 0 0

Im having the same issue, even though the access is being provided in the .toml file

SBD_
Shopify Staff
1829 272 417

Hey @cvargas31 

 

Have you restarted + followed these steps?

Scott | Developer Advocate @ Shopify