New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to get sessionToken in Admin block/action Extension

Solved
nhtbao101
New Member
12 0 0

I am using Shopify Admin action extension and using network access outside Shopify.
In the web/front-end folder, I create authenic and I can get session in here.
But in the admin extension folder, I tried to import the authentic function from web/front-end folder to there but it's not working.

 

My structure:

--extension

   --admin-action-extension

      --index.ts

--web

  --frontend

     --authenticate

        --index.ts

Please help me. I was stack here in 3 days

Accepted Solution (1)
lizk
Shopify Staff
Shopify Staff
246 57 62

This is an accepted solution.

Thank you for confirming your use case!

If you are making API calls to your apps backend, when you use fetch() to make a request to your app's configured auth domain or any of its subdomains, an Authorization header is automatically added with a Shopify OpenID Connect ID Token. There's no need to manually manage session tokens. Docs here

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 5 (5)
lizk
Shopify Staff
Shopify Staff
246 57 62

Hi there 👋

If you are inside of an Admin Action Extension and you want to make an API call to Shopify you can use Direct API Access. 

Any fetch() calls to Shopify's Admin GraphQL API from your extension are automatically authenticated by default.

You can review this tutorial on using Direct API Access from within Admin Action extension

To learn more visit the Shopify Help Center or the Community Blog.

nhtbao101
New Member
12 0 0

Thank for your reply but I don't want to make a call API to Shopify's Admin, I created an API outside from another server and I want to make a call API to there

lizk
Shopify Staff
Shopify Staff
246 57 62

This is an accepted solution.

Thank you for confirming your use case!

If you are making API calls to your apps backend, when you use fetch() to make a request to your app's configured auth domain or any of its subdomains, an Authorization header is automatically added with a Shopify OpenID Connect ID Token. There's no need to manually manage session tokens. Docs here

To learn more visit the Shopify Help Center or the Community Blog.

minsko
Shopify Partner
17 1 0

@nhtbao101 Is this solution working for you?  I am using fetch(app:/path) from an admin extension, but am not getting an Authorization header sent with the request. https://community.shopify.com/c/authentication-and-access/authorization-header-not-sent-with-fetch-f...

minsko
Shopify Partner
17 1 0

Nevermind.  I am now getting the header.