Could anyone please tell me how can I get the user account shop name

I need to give a service in my app where user can connect their account and we fetcha and verify data on their behalf. But OAuth2 api authentication need shop name. How can I get that dynamically for each account?

Which programming language are you using? If the request comes from your Shopify application, and you use app bridge to make these requests then (in Node) you can do a couple of things:

  • Check if the shop is part of the query (which it should be in requests coming from a Shopify app) (recommended)
import { Shopify } from '@shopify/shopify-api';

const shop = Shopify.Utils.sanitizeShop(req.query.shop);​
  • Manually extract it from the Bearer token that is in the request (less recommended)
import { Shopify } from '@shopify/shopify-api';

const authHeader = req.headers['authorization']?.substring('Bearer '.length);
const decoded = Shopify.Utils.decodeSessionToken(authHeader);
const shopName = decoded?.dest;​